Re: [R] how to add a column from another dataset with merge

2012-12-07 Thread Pete Brecknock
kiotoqq wrote I want to add a shorter column to my dataset with the function merge, it should be filled with NAs wo be as long as the other colums, like this: idage 946 856 6 52 5 NA 4 NA 3 NA 1 NA i did this: pa1 - merge(pa1, an1, by=mergeid) and it says

Re: [R] how to add a column from another dataset with merge

2012-12-07 Thread arun
Hi, You could use sort=FALSE in ?merge() d1-data.frame(id=c(9,8,6,5,4,3,1)) d2-data.frame(id=c(9,8,6),age=c(46,56,52))  d-merge(d1,d2,all.x=TRUE,sort=FALSE) #or library(plyr) join(d1,d2,by=id,type=full) #  id age #1  9  46 #2  8  56 #3  6  52 #4  5  NA #5  4  NA #6  3  NA #7  1  NA A.K. -