Re: [R] How to join data.frames with different row lengths

2014-03-24 Thread Johnson
Thank you Arun Kirshna. That worked perfectly! On Mon, Mar 24, 2014 at 2:49 PM, arun kirshna [via R] < ml-node+s789695n4687459...@n4.nabble.com> wrote: > Hi, > Try ?merge() or ?join from library(plyr) > If `dat1` and `dat2` are the datasets: > res <- merge(dat1,dat2,by="Code",all=TRUE) > res[is

Re: [R] How to join data.frames with different row lengths

2014-03-24 Thread David Barron
You'll have to do this in two stages. The merge is just a case of specifying all=TRUE: data1 <- data.frame(Code=c(2,6,7,17), Cap04=c(120,75,220,4)) data2 <- data.frame(Code=c(2,7,9,17), Cap08=c(120,112,190,4)) data.merge <- merge(data1,data2, all=TRUE) data.merge Code Cap04 Cap08 12 120

Re: [R] How to join data.frames with different row lengths

2014-03-24 Thread arun
Hi, Try ?merge() or ?join from library(plyr) If `dat1` and `dat2` are the datasets: res <- merge(dat1,dat2,by="Code",all=TRUE)  res[is.na(res)] <- 0  res #  Code Cap04 Cap08 #1    2   120   120 #2    6    75 0 #3    7   220   112 #4    9 0   190 #5   17 4 4 A.K. Hello, I need t