0

I have the following data frame. I would like to convert the rows into two columns in R

>10890
 RNA 1
 RNA 2    

>1318
  RNA 1
  RNA 2
  RNA 3

I want to convert it in to two columns

Column 1      Column 2
10890          RNA 1
10890          RNA 2
1318           RNA 1
1318           RNA 2
1318           RNA 3
eddi
  • 49,088
  • 6
  • 104
  • 155
user2498657
  • 379
  • 2
  • 6
  • 16
  • 2
    I reformated your post but it's still unclear what kind of data structures you have; see this post for posting guidelines http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5965451 – eddi Jun 28 '13 at 18:52
  • I actually have the data in a single column. I want to split the data in two columns as mentioned above. – user2498657 Jun 28 '13 at 19:03
  • @user2498657 Can you give a shortened example or some of your data? – dayne Jun 28 '13 at 19:06

1 Answers1

0

Without having a reproducible example, it's hard to say, but you may want to look at ?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"

You could also look at the reshape2 package.

It kind of looks like you have your data in a list. Assuming you have your data in a list you could do the following:

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" 
dayne
  • 7,504
  • 6
  • 38
  • 56
  • I am sorry to bug you again but this particular but I want the integer id s to duplicate. This particular example returns unique integer ids – user2498657 Jun 28 '13 at 19:16
  • @user2498657 You have to give a reproducible example of your data, or I am not going to be able to do anymore. Please edit your question and include - as I have in my answer - a line of code that I or someone else can load into R and use to find a solution. – dayne Jun 28 '13 at 19:19
  • Actually I am reading data from a huge data file. But I am really thankful for your help – user2498657 Jun 28 '13 at 19:24
  • 1
    @user2498657 It doesn't matter what you're reading from. What you need to do is what I did. Create an example, manually, in R that reflects the data you have loaded it. You should really take some time and read about how to participate on SO if you're going to continue asking questions. – dayne Jun 28 '13 at 19:26
  • @user2498657 Please refer to the link eddi gave you in his or her comment to your question. – dayne Jun 28 '13 at 19:28