Did you have something like this in mind? #prepare the data traits <- data.frame(letters[1:9], sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9), sample(letters, 9)) colnames(traits) <- c("species", 1:8) comcops <- data.frame(community = paste("com", rep(1:3, each = 3), sep = ""), species = sample(letters[1:9], 9, replace = TRUE))
> traits species 1 2 3 4 5 6 7 8 1 a c u j f e x w s 2 b k w w v m l d k 3 c j x q r a t a n 4 d b v o w p o c a 5 e h g g a n n r d 6 f x d b p v i p j 7 g r i m k g r l v 8 h p l n l t p m z 9 i g a l d x h z q > comcops community species 1 com1 f 2 com1 c 3 com1 b 4 com2 c 5 com2 a 6 com2 h 7 com3 h 8 com3 d 9 com3 e all(comcops$species %in% traits$species) #check #mambo jumbo traits[as.character(comcops$species), ] mix.all <- apply(comcops, 1, function(x, df.traits) { out <- df.traits[which(df.traits$species == x[2]), ] return(out) }, df.traits = traits) mix.all <- do.call("rbind", mix.all) final <- cbind(community = comcops$community, mix.all) > split(final, final$community) $com1 community species 1 2 3 4 5 6 7 8 6 com1 f x d b p v i p j 3 com1 c j x q r a t a n 2 com1 b k w w v m l d k $com2 community species 1 2 3 4 5 6 7 8 31 com2 c j x q r a t a n 5 com2 a c u j f e x w s 8 com2 h p l n l t p m z $com3 community species 1 2 3 4 5 6 7 8 81 com3 h p l n l t p m z 4 com3 d b v o w p o c a 51 com3 e h g g a n n r d To maximize your chances of getting a reply, I would suggest you provide the list with a minimal working example of (fake) data you're working with. Cheers, Roman On Thu, Jan 6, 2011 at 12:39 PM, Peter Francis <peterfran...@me.com> wrote: > 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-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > -- In God we trust, all others bring data. [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology