作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的数据框中有一列:
Colname
20151102
19920311
20130204
>=70
60-69
20-29
我想将这一列分成两列,例如:
Col1 Col2
20151102
19920311
20130204
>=70
60-69
20-29
我怎样才能达到这个结果?
最佳答案
不需要任何包:
df[,c("Col1", "Col2")] <- ""
isnum <- suppressWarnings(!is.na(as.numeric(df$colname)))
df$Col1[isnum] <- df$colname[isnum]
df$Col2[!isnum] <- df$colname[!isnum]
df <- df[,!(names(df) %in% "colname")]
数据:
df = data.frame(colname=c("20151102","19920311","20130204",">=70","60-69","20-29"), stringsAsFactors=FALSE)
关于regex - 如何将单列中的内容拆分为 R 中的两个单独的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28317155/
我是一名优秀的程序员,十分优秀!