[R] How to select specific rows from a data frame based on values

Arin Basu arin.basu at gmail.com
Thu May 17 19:59:57 CEST 2007


Dear Group:

I am working with a data frame containing 316  rows of individuals
with 79 variables. Each of these 79 variables have values that range
between -4 to +4, and I want to subset this data frame so that in the
resulting new dataframe, values of _all_ of these variables should
range between -3 and +3.

Let's say I have the following dataframe (it's a toy example with 4
individuals and 5 variables):

subj1 <- cbind(-4, -3, -1, -5, -7)
subj2 <- cbind(-2, -1, -1, -2, +2)
subj3 <- cbind(+2, +1, +2, +1, +2)
subj4 <- cbind(-4, -1, -2, +2, +1, +1)

mydf <- as.data.frame(rbind(subj1, subj2, subj3, subj4))

>From mydf, I want to generate a new dataframe (let's call it mydf1)
which will have records of only subj2 and subj3 in it since only these
two individuals had all values for variables V1 through V5 in mydf to
range between -3 and +3.

Documentation on subsetting and indexing data frames did not help to
solve this specific problem. There may be an obvious solution to it
but I just cannot seem to get it.

Would greatly appreciate your inputs.

[relevant information: R-version: 2.4.1, running on Windows XP]

/Arin Basu



More information about the R-help mailing list