s-news
[Top] [All Lists]

Re: A subset question

To: Bert Jacobs <b.jacobs@pandora.be>, s-news@lists.biostat.wustl.edu
Subject: Re: A subset question
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Sat, 11 Jun 2005 21:50:18 -0400
## You are not using the word "factor" as it is used in standard S
## language terminology.  I translate your question as follows:
## 
## I have a dataframe y with 124 variables.  I would like to create a
## subset of rows of this dataframe by selecting a number of levels of
## the data.frame factor "HOSP".  The levels I wish to use in the subset
## can be found in a vector x.
## 
## If I have interpreted your question correctly, here is the answer.
## 
## If this is not what you want then please resubmit your request to the
## list with a simple executable set of S statements for a smaller
## example.  Show the y data.frame including the factor HOSP.  Give the
## vector x.  Show us exactly what you expect to see in your result.



y <- data.frame(aa=rnorm(12),
                bb=factor(rep(letters[1:3],4)),
                HOSP=factor(rep(LETTERS[1:4],3)),
                dd=factor(sample(letters[1:5], 12, replace=T)))

x <- c("A","B")


subset.rows <- (match(y$HOSP, x, 0) > 0)

result <- y[subset.rows, ]
result

<Prev in Thread] Current Thread [Next in Thread>
  • Re: A subset question, Richard M. Heiberger <=