[R] Simple operation on a subset of data
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Fri Nov 12 13:30:46 CET 2004
Hi Giacomo,
"An Introduction to R" is very useful document for all these things!
Look at ?subset and try:
dat <- data.frame(x=sample(1:2, 10, TRUE), y=sample(c(4,5), 10, TRUE),
z=rnorm(10))
######
summary(dat$z)
summary(subset(dat, x==1 & y==4, select=z))
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Giacomo De Giorgi " <uctpgde at ucl.ac.uk>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, November 12, 2004 1:04 PM
Subject: [R] Simple operation on a subset of data
> Sorry for the silly question.
>
> I am trying to perform a simple operation on a subsample of my data
> loaded as data and attached:
>
> data<-read.dta(name file)
> attach(data)
>
> Say x=1,2 and y=4,5 I want to summarize z only if x=1 & y=4. I
> thought
> that the way to do that would be to
> write if((x=1) & (y=4)) summary(z)
> butwhen I do this the result I get is for the whole data
> (irrespective
> of the conditions imposed). Can anyone help?
>
>
> Thanks
> Giacomo
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>
More information about the R-help
mailing list