0

我有以下数据框。我想将行转换为 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
4

1 回答 1

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" 
于 2013-06-28T18:59:17.573 回答