You're definitely doing something I don't understand. Here's a quick mock-up of the sample data sets you provided. How do you know if species a in trait is from NA1102 or AT1302 in com? I may be blind but I just don't see what you're matching when you use which. Perhaps you might want to post the which command you're using?
By the way dput is a valuable way of providing sample data. trait <- structure(list(Species = c("a", "b", "c"), v1 = c("t", "f", "r" ), v2 = c("y", "j", "y"), v3 = c("h", "u", "u")), .Names = c("Species", "v1", "v2", "v3"), class = "data.frame", row.names = c(NA, -3L )) com <- structure(list(community = c("NA1102", "NA1102", "NA0402", "NA0402", "AT1302", "AT1302"), species = c("a", "c", "b", "c", "a", "b" )), .Names = c("community", "species"), class = "data.frame", row.names = c(NA, -6L)) > From: Chris Mcowen <chrismco...@gmail.com> > Subject: Re: [R] Multiple subsets of data > To: "John Kane" <jrkrid...@yahoo.ca> > Cc: r-help@r-project.org > Received: Thursday, January 6, 2011, 10:19 AM > Hi, > > Sorry the formatting has messed up, the common variable is > species ( spelt different in both but i have corrected this > now) > > I am having some luck with the which function but am > struggling to automate it for all communities > On 6 Jan 2011, at 15:09, John Kane wrote: > > Is there any common variable? From your description, > I don't see how you would link a species to a > community. I mean if you select species a in df1 how > would you know what community it is in? > > --- On Thu, 1/6/11, Chris Mcowen <chrismco...@gmail.com> > wrote: > > > From: Chris Mcowen <chrismco...@gmail.com> > > Subject: [R] Multiple subsets of data > > To: r-help@r-project.org > > Received: Thursday, January 6, 2011, 6:29 AM > > Dear List, > > > > I have a data frame called trait with roughly 800 > species > > in, each species have 15 columns of information: > > > > Species > > 1 2 3 > > etc.. > > a > > t y h > > b > > f j u > > c > > r y u > > > > etc.. > > > > > > I then have another data frame called com with the > > composition of species in each region, there are 506 > > different communities: > > > > community species > > NA1102 a > > NA1102 c > > NA0402 b > > NA0402 c > > AT1302 a > > AT1302 b > > > > etc.. > > > > > > What i want to do is extract the information held in > the > > first data frame for each community and save this as a > new > > data frame. > > > > Resulting in : - > > > > community_NA1102 > > > > a > > t y h > > c > > r y u > > > > community_NA0402 > > > > b > > f j u > > c > > r y u > > > > Thanks in advance for any suggestions / code. > > ______________________________________________ > > 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-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.