-1

I have a data frame as following and I want to intersect them to become one column.

ID<-c('>1','>2','>3','>4','>5')
TYPE<-c('A','B','O','A','B')
old<-data.frame(ID,TYPE)
old

  ID TYPE
  >1    A
  >2    B
  >3    O
  >4    A
  >5    B

I want to merge them and become a new data set to look like this.

  NEW_VAR 
  >1  
   A  
  >2    
   B
  >3    
   O
  >4    
   A
  >5    
   B

I try the following code, but it does not work.

intersect(old$ID, old$TYPE)

But it shows

character(0)

Thanks in advance.

Terence Tien
  • 329
  • 1
  • 3
  • 15
  • 3
    I would call that a interleaving, there are several similar questions if you [search for that term instead](http://stackoverflow.com/questions/13400931/interleave-two-columns-of-a-data-frame) – rawr Jun 24 '16 at 23:11
  • why do you want it this way – Señor O Jun 24 '16 at 23:13

1 Answers1

3

For the desired result you could try:

c(t(old))
 [1] ">1" "A"  ">2" "B"  ">3" "O"  ">4" "A"  ">5" "B" 
DatamineR
  • 10,428
  • 3
  • 25
  • 45