[R] Simple operation on a subset of data
Thomas Lumley
tlumley at u.washington.edu
Fri Nov 12 16:40:36 CET 2004
On Fri, 12 Nov 2004, Giacomo De Giorgi wrote:
>
> 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?
There are actually worse problems with
if((x=1) & (y=4)) summary(z)
than that: you have just set x to 1 and y to 4.
You can do
summary(z[(x==1) & (y==4)])
to get the answer you want (or various other things)
You really need to read the Introduction to R, which will tell you, among
other things, what the = operator does.
-thomas
More information about the R-help
mailing list