[R] merging unbalanced rows
R. Michael Weylandt
michael.weylandt at gmail.com
Mon May 21 17:07:56 CEST 2012
I think you want this:
merge(a,b, by = "d", all = FALSE)
Type ?merge to see all the options to merge available to you,
Best,
Michael
On Mon, May 21, 2012 at 9:31 AM, Belay Gebregiorgis <belayg12 at gmail.com> wrote:
> Hi Everyone,
>
> I am merging two data frames that have different number of rows. But I end
> up having rows a lot more than both rows combined. I tried the following
> but the duplicate bit does not change anything. Can anyone suggest to me
> how I can handle this?
>
> Regards,
> Belay
>
>
> x <-c(1, 2, 3, 4,5, NA, NA,NA,NA,10)
> y <-c( NA, 4,NA,5,2, 10, 7, 1, 8, 9)
> d<-1:10 #### this one belongs to the data frame a
> d<-1:5 #### this one belongs to the data frame b
> s1<-1:5
> s2<-6:10
>
> a<-data.frame(x,y,d)
> b<- data.frame(s1,s2,d)
>
> c<-merge(a, b, by=c("d"))
>
> c[!duplicated(c[,c("x","y")]),]
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list