Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.61b.0411120734230.157858@homer07.u.washington.edu>
Date: 2004-11-12T15:40:36Z
From: Thomas Lumley
Subject: Simple operation on a subset of data
In-Reply-To: <001501c4c8af$ba809f00$db5a2880@economics.ucl.ac.uk>

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