Re: [R] biding rows while merging at the same time
On Nov 3, 2010, at 5:38 PM, Dimitri Liakhovitski wrote: Never mind - I found it in "reshape" package: rbind.fill I wonder if it's still in reshape2. Look in plyr. -- David. Dimitri __ 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] biding rows while merging at the same time
Just merge(df1, df2, all = TRUE) does it, yes? Dimitri Liakhovitski wrote: Hello! I have 2 data frames like this (well, actually, I have 200 of them): df1<-data.frame(location=c("loc 1","loc 2","loc 3"),date=c("1/1/2010","1/1/2010","1/1/2010"), a=1:3,b=11:13,c=111:113) df2<-data.frame(location=c("loc 1","loc 2","loc 3"),date=c("2/1/2010","2/1/2010","2/1/2010"), a=4:6,c=114:116,d=c(1,11,111)) (df1) (df2) I am trying to just rbind them, which is impossible, because not every column is present in every data frame. I can't merge them - merge(df1,df2,by.x="location",by.y="location",all.x=T,all.y=T) - because it kinda cbinds them. What I need is something that looks like this: location datea b c d loc 1 1/1/2010 1 11 111 NA loc 2 1/1/2010 2 12 112 NA loc 3 1/1/2010 3 13 113 NA loc 1 2/1/2010 3 NA 114 1 loc 2 2/1/2010 5 NA 115 11 loc 3 2/1/2010 6 NA 116 111 Thanks a lot for your suggestions! __ 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] biding rows while merging at the same time
Never mind - I found it in "reshape" package: rbind.fill I wonder if it's still in reshape2. Dimitri On Wed, Nov 3, 2010 at 5:34 PM, Dimitri Liakhovitski wrote: > Hello! > > I have 2 data frames like this (well, actually, I have 200 of them): > > df1<-data.frame(location=c("loc 1","loc 2","loc > 3"),date=c("1/1/2010","1/1/2010","1/1/2010"), a=1:3,b=11:13,c=111:113) > df2<-data.frame(location=c("loc 1","loc 2","loc > 3"),date=c("2/1/2010","2/1/2010","2/1/2010"), > a=4:6,c=114:116,d=c(1,11,111)) > (df1) > (df2) > > I am trying to just rbind them, which is impossible, because not every > column is present in every data frame. > I can't merge them - > merge(df1,df2,by.x="location",by.y="location",all.x=T,all.y=T) - > because it kinda cbinds them. > What I need is something that looks like this: > > location date a b c d > loc 1 1/1/2010 1 11 111 NA > loc 2 1/1/2010 2 12 112 NA > loc 3 1/1/2010 3 13 113 NA > loc 1 2/1/2010 3 NA 114 1 > loc 2 2/1/2010 5 NA 115 11 > loc 3 2/1/2010 6 NA 116 111 > > Thanks a lot for your suggestions! > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ 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.
[R] biding rows while merging at the same time
Hello! I have 2 data frames like this (well, actually, I have 200 of them): df1<-data.frame(location=c("loc 1","loc 2","loc 3"),date=c("1/1/2010","1/1/2010","1/1/2010"), a=1:3,b=11:13,c=111:113) df2<-data.frame(location=c("loc 1","loc 2","loc 3"),date=c("2/1/2010","2/1/2010","2/1/2010"), a=4:6,c=114:116,d=c(1,11,111)) (df1) (df2) I am trying to just rbind them, which is impossible, because not every column is present in every data frame. I can't merge them - merge(df1,df2,by.x="location",by.y="location",all.x=T,all.y=T) - because it kinda cbinds them. What I need is something that looks like this: location datea b c d loc 1 1/1/2010 1 11 111 NA loc 2 1/1/2010 2 12 112 NA loc 3 1/1/2010 3 13 113 NA loc 1 2/1/2010 3 NA 114 1 loc 2 2/1/2010 5 NA 115 11 loc 3 2/1/2010 6 NA 116 111 Thanks a lot for your suggestions! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ 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.