Re: [R] merge data frames with same column names of differe nt lengths and missing values
Steven Lubitz slubitz1 at yahoo.com writes: Thank you - this is very helpful. However I realized that with my real data sets (not the example I have here), I also have different numbers of columns in each data frame. rbind doesn't seem to like this. Here's a modified example: x - data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), item3=c(NA,2,NA,4,NA), id=1:5) y - data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6) rbind(x,y) You should add dummy NA variables to each partial data frame such that they look the same, and do the rbind later. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge data frames with same column names of differe nt lengths and missing values
Steven Lubitz slubitz1 at yahoo.com writes: x - data.frame(item1=c(NA,NA,3,4,5), item2=c(1,NA,NA,4,5), id=1:5) y - data.frame(item1=c(NA,2,NA,4,5,6), item2=c(NA,NA,3,4,5,NA), id=1:6) merge(x,y,by=c(id,item1,item2),all.x=T,all.y=T) #my rows are duplicated and the NA values are retained - I instead want one row per ID id item1 item2 1 1NA 1 2 1NANA 3 2 2NA 4 2NANA 5 3 3NA 6 3NA 3 7 4 4 4 8 5 5 5 9 6 6NA I think you only got the wrong (too complex) function. Try rbind(x,y) Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.