[英]insert new line to the top of table r
I've these two tables: 我有这两个表:
1003 1 0 0 2 0 0 0 0 0 0 0 0 0
1003 2 0 0 1 0 0 0 0 0 0 0 0 0
1003 3 2 1 2 2 1 2 1 2 0 0 0 0
1003 4 2 1 1 2 1 1 1 1 0 0 1 1
and 和
snp1 1
snp2 2
snp3 3
snp4 4
and I want to add using R the first column of the second table as line in the top of the first table: 并且我想使用R将第二个表的第一列添加为第一个表顶部的行:
snp1 snp2 snp3 snp4
1003 1 0 0 2 0 0 0 0 0 0 0 0 0
1003 2 0 0 1 0 0 0 0 0 0 0 0 0
1003 3 2 1 2 2 1 2 1 2 0 0 0 0
1003 4 2 1 1 2 1 1 1 1 0 0 1 1
Please help, thank you a lot. 请帮忙,非常感谢你。
Your question is a little vague. 你的问题有点模糊。 Is
snp1...snp4
supposed to be some sort of column header? 是
snp1...snp4
应该是某种列标题? What about the other columns from the first table? 第一张表中的其他列怎么样? What's supposed to be filled in there?
什么应该填补在那里? I somehow doubt this is really what you want to do, but this does in fact answer your question:
我怀疑这是你想要做的,但实际上这确实回答了你的问题:
#table 1
x1 <- read.table(text = "1003 1 0 0 2 0 0 0 0 0 0 0 0 0
1003 2 0 0 1 0 0 0 0 0 0 0 0 0
1003 3 2 1 2 2 1 2 1 2 0 0 0 0
1003 4 2 1 1 2 1 1 1 1 0 0 1 1", header = FALSE)
#table 2
x2 <- read.table(text = "snp1 1
snp2 2
snp3 3
snp4 4", header = FALSE)
#insert the first column of table 2 into the first row of table 1
x3 <- rbind(c(as.character(x2[,1]), rep(NA, ncol(x1) - nrow(x2))), x1)
Resulting in: 导致:
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14
1 snp1 snp2 snp3 snp4 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
2 1003 1 0 0 2 0 0 0 0 0 0 0 0 0
3 1003 2 0 0 1 0 0 0 0 0 0 0 0 0
4 1003 3 2 1 2 2 1 2 1 2 0 0 0 0
5 1003 4 2 1 1 2 1 1 1 1 0 0 1 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.