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

From: Arin Basu <arin.basu_at_gmail.com>
Date: Thu, 17 May 2007 23:29:57 +0530


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



R-help_at_stat.math.ethz.ch 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. Received on Thu 17 May 2007 - 18:11:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 May 2007 - 19:30:56 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.