Re: [R] Merging two data frames, but keeping NAs

2013-12-06 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/05/13, 16:37 , arun wrote: > Hi, Try ?join() > > library(plyr) Well - what would we do without Hadley ... He solved many problems we didn't know we would have soon... Cheers, Rainer > y$ref <- y$id >> join(x,y,by="ref") > ref id val 1 N

Re: [R] Merging two data frames, but keeping NAs

2013-12-06 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/05/13, 16:11 , Sarah Goslee wrote: > Adding the argument all.x=TRUE to merge() will retain the NA > values, but the only reliable way I've found to preserve order with > NA values in a merge is to add an index column to x, merge the > data, sort

Re: [R] Merging two data frames, but keeping NAs

2013-12-05 Thread arun
Hi, Try ?join() library(plyr) y$ref <- y$id > join(x,y,by="ref")    ref id val 1   NA NA  NA 2   NA NA  NA 3   NA NA  NA 4   10 NA  NA 5    9  9 106 6    8  8 107 7    7  7 105 8    6  6 104 9    5 NA  NA 10  NA NA  NA 11   1 NA  NA 12   2  2 101 13   3  3 102 14   4  4 103 15   5 NA  NA A.K.

Re: [R] Merging two data frames, but keeping NAs

2013-12-05 Thread Sarah Goslee
Adding the argument all.x=TRUE to merge() will retain the NA values, but the only reliable way I've found to preserve order with NA values in a merge is to add an index column to x, merge the data, sort on the index column, then delete it. Sarah On Thu, Dec 5, 2013 at 9:56 AM, Rainer M Krug wrot

[R] Merging two data frames, but keeping NAs

2013-12-05 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi My brain is giving up on this... I have the following two data.frames: x <- data.frame(ref=c(NA, NA, NA, 10:5, NA, 1:5)) y <- data.frame(id = c(2, 3, 4, 6, 7, 9, 8), val = 101:107) Which look as follow: > x ref 1 NA 2 NA 3 NA 4