[S] Obtaining a subset of a data frame / matrix

Fri, 20 Mar 1998 09:22:10 -0700

I have a rather simple question that has probably been asked before. I would
like to create a dataset that is simply a subset of a current dataset without
having to manipulate each variable in the dataset. Here is a very simple

treeno diam ht species
1 10 20 1
2 11 21 0
3 12 22 1
4 13 23 0
5 14 24 1

I would like the new dataset to contain observations where species=1 and
ht>21. There are a couple of ways to do this, here is one way:

newdata_data.frame(cbind(tempdata$treeno[tempdata$species==1 &
tempdata$ht>21], tempdata$diam[tempdata$species==1 & tempdata$ht>21],
tempdata$ht[tempdata$species==1 & tempdata$ht>21],
tempdata$species[tempdata$species==1 & tempdata$ht>21]))
names(newdata)_c("treeno", "diam", "ht", "species")

Is there a better way to do this? One that does not require manipulation of
each variable? In my discussion with other S-Plus users I haven't come across
anyone who has found a much better way to do this - but I'm sure there is a
better solution.

Thanks for the help!!!

Laurie Porth
Rocky Mountain Experiment Station
USDA Forest Service
Fort Collins, Colorado

This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news