我的数据集包含两列数据偏移的数据 - 类似于:
col1<-c("a", "b", "c", "d", "ND", "ND", "ND", "ND")
col2<-c("ND", "ND", "ND", "ND", "e", "f", "g", "h")
dataset<-data.frame(cbind(col1, col2))
我想将这两个偏移列合并为一个列,其中包含字母 a 到 h,仅包含其他内容。
我的想法如下,但 rbind 不是正确的命令:
dataset$combine<-rbind(dataset$col1[1:4], dataset$col2[5:8])
最佳答案
关于:
sel2 <- col2!="ND"
col1[sel2] <- col2[sel2]
> col1
[1] "a" "b" "c" "d" "e" "f" "g" "h"
关于r - 如何将两列与偏移数据合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13805769/