But better without calling your new data frame "subset" since it's a function as well.

-----Original Message-----

From:

r-help-bounces@r-project.org on behalf of Schreiber, Stefan

Sent: Thu 1/12/2012 8:50 PM

To: Marc Schwartz; R. Michael Weylandt

Cc:

r-help@r-project.org; manu79

Subject: Re: [R] work with a subset of the dataset

Or with what I just learned:

subset<-[mydata$age %in% c(20:30),]

Thanks for explaining Michael!

Stefan

-----Original Message-----

From:

r-help-bounces@r-project.org on behalf of Marc Schwartz

Sent: Thu 1/12/2012 8:38 PM

To: R. Michael Weylandt

Cc:

r-help@r-project.org; manu79

Subject: Re: [R] work with a subset of the dataset

Presuming that 'DF' is the data frame, I am not sure what is wrong with

NewDF <- subset(DF, (age >= 20) & (age <= 30))

presuming that 20 and 30 are to be included.

?

Marc Schwartz

On Jan 12, 2012, at 9:26 PM, R. Michael Weylandt wrote:You can probably do it more easily with the subset() function but in

my experience that often leads to more problems than solutions:

perhaps try this.

idx <- with(DATA, which(age > 20 & age < 30))

DATA[idx, ]

Michael

On Thu, Jan 12, 2012 at 5:25 PM, manu79 wrote:

Hello,

I have a big dataset with many variables and I would like to consider only

the rows in which there is a specific value of a variable.

I make an example for explain what I mean:

I have 5 variables describing a person: age, sex, weight, colour of hair,

colour of eyes.

I have 1000 rows (1000 persons) and I want to consider only the persons

whose age is between 20 to 30. How can I do?

Thank you very much

M.

______________________________________________

r-help@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

______________________________________________

r-help@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.