我有以下数据框。我想将行转换为R
中的两列>10890
RNA 1
RNA 2
>1318
RNA 1
RNA 2
RNA 3
我想将其转换为两列
Column 1 Column 2
10890 RNA 1
10890 RNA 2
1318 RNA 1
1318 RNA 2
1318 RNA 3
答案 0 :(得分:0)
如果没有可重复的例子,很难说,但你可能想看看?t
example <- data.frame("sample"=c("RNA1","RNA2","RNA3"),"value"=rnorm(3,0,1))
example
sample value
1 RNA1 0.7666676
2 RNA2 0.6275869
3 RNA3 -2.7513690
t(example)
[,1] [,2] [,3]
sample "RNA1" "RNA2" "RNA3"
value " 0.7666676" " 0.6275869" "-2.7513690"
您还可以查看reshape2
包。
看起来你有一个列表中的数据。假设您在列表中包含数据,则可以执行以下操作:
example.list <- list("10848"=c("RNA1","RNA2","RNA3"),"3056"=c("RNA1","RNA2"))
cbind(unlist(example.list),names(unlist(example.list)))
[,1] [,2]
108481 "RNA1" "108481"
108482 "RNA2" "108482"
108483 "RNA3" "108483"
30561 "RNA1" "30561"
30562 "RNA2" "30562"