Hi, everyone

I met a small problem when I want take a subset from a data frame. The data frame(x) looks like the followings(10 species with 3 measured traits):

Species     trait1    trait2     trait3
sp1
sp1
...
sp2
sp2
...

sp10
sp10
...

It would be easy if we want trait values for most abundant species, we can do that with the following codes

sp<-table(x$Species)
x[x$Species==names(sp)[1],]

but why it doesn't work if we want to select traits values for more than one species(most abundant two species) with similar codes

x[x$Species==names(sp)[1:2],]

And there must be other solutions for this problem. Looking forward for your help.

Thanks in advance!

______________________________________________
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.

Reply via email to