[R] subset

Marc Schwartz marc_schwartz at comcast.net
Mon Mar 26 17:42:42 CEST 2007


Sergio,

Please be sure to cc: the list (ie. Reply to All) with follow up
questions.

In this case, you would use %in% with a negation:

NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (!var3 %in% 2:3)) 

See ?"%in%" for more information.

HTH,

Marc

On Mon, 2007-03-26 at 17:30 +0200, Sergio Della Franca wrote:
> Ok, this run correctly.
>  
> Another question for you:
>  
> I want to put more than one condition for var3, i.e.:
> I like to create a subset when:
>  - var1=0
>  - var2=0
>  - var3 is different from 2 and from 3.
>  
> Like you suggested, i perform this code:
> NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (var 3 != 2)) & (var
> 3 != 3))
>  
> There is a method to combine (var 3 != 2)) & (var 3 != 3)) in one
> condition?
>  
> Thank you.
>  
> Sergio
>  
> 
>  
> 2007/3/26, Marc Schwartz <marc_schwartz at comcast.net>: 
>         On Mon, 2007-03-26 at 17:02 +0200, Sergio Della Franca wrote:
>         > Dear R-Helpers,
>         >
>         > I want to make a subset from my data set. 
>         >
>         > I'd like to perform different condition for subset.
>         >
>         > I.e.:
>         >
>         > I like to create a subset when:
>         > - var1=0
>         > - var2=0
>         > - var3 is different from 2.
>         >
>         > How can i develop a subset under this condition?
>         >
>         > Thank you in advance.
>         >
>         > Sergio Della Franca.
>         
>         See ?subset
>         
>         Something along the lines of the following should work:
>         
>         NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (var 3 != 0)) 
>         
>         HTH,
>         
>         Marc Schwartz



More information about the R-help mailing list