Hi R users, I am trying to extract some attributes (age, sex, area) from dataframe "AB" that has 101,269 observations of 28 variables to dataframe "t2" that has 47 observations of 6 variables. They share a column called "id", which is a factor with 47 levels. I want to end up with a dataframe that has 47 observations of 9 variables (the original 6 variables of t2, plus age, sex, and area). The issue I am having is that in AB has multiple entries for each id, and so I can't use merge because there is more than one match, so all possible matches contribute one row each--i.e., this code gives me dataframe "t3" of 101,269 observations of 33 variables:
>t3<-merge(t2,AB,by="id",all=FALSE) Dataframe AB (24 variables omitted from example dataframe): id sex age area 01 male adult LP 01 male adult LP 01 male adult LP ... 02 female subadult LP 02 female subadult LP 02 female subadult LP 02 female subadult LP ... 03 male subadult MR 03 male subadult MR 03 male subadult MR 03 male subadult MR ... Dataframe t2 (5 variables omitted from example dataframe): id 01 02 03 04 05 06 .... This is the structure I want for dataframe t3 (5 variables omitted from example dataframe): id sex age area 01 male adult LP 02 female subadult LP 03 male subadult MR ... Hopefully this all makes sense and someone knows a solution. Thanks in advance for taking a look at my problem and helping out (I hope!). Nathaniel -- View this message in context: http://r.789695.n4.nabble.com/Need-help-merging-two-dataframes-tp3297313p3297313.html Sent from the R help mailing list archive at Nabble.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.