0

I am trying to merge columns but facing a wierd issue.

Error in fix.by(by.y, y) : 'by' must specify uniquely valid column(s)

I am pasting an example of expected result.

Table.one               
col1    col2    col3    col4    
a   34  76  gdfg    
b   345 56987   fdg 
c   323 5987    dfgd    
a   151 51651   sfg 
b   156 515616  sg  
c   51  5156    gdfg    

Table.two               
col1    col5            
a   12          
b   15          
c   15          
d   12          
e   158         

"Want result"

col1    col2    col3    col4    col5
a   34  76  gdfg    12
b   345 56987   fdg 15
c   323 5987    dfgd    15
a   151 51651   sfg 12
b   156 515616  sg  15
c   51  5156    gdfg    15

I used y<-merge(Table.one,Table.two,by="col1",all.x=T)

but doesn't work. Does someone have a remedy.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93

1 Answers1

0

I get the result as shown in "want result" using merge. Used join to preserve the order of rows.

library(plyr)
 join(tb1,tb2, by="col1")
 col1 col2   col3 col4 col5
 1    a   34     76 gdfg   12
 2    b  345  56987  fdg   15
 3    c  323   5987 dfgd   15
 4    a  151  51651  sfg   12
 5    b  156 515616   sg   15
 6    c   51   5156 gdfg   15
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
akrun
  • 874,273
  • 37
  • 540
  • 662