[R] Multiple logical operations in a subscript

Mark Na mtb954 at gmail.com
Fri Sep 19 02:10:39 CEST 2008


Hello,

I would like to select cases using multiple logical operations (e.g. X 
or Y or Z) without having to repeat the dataframe$variable within the 
subscript. My working code (with a single logical operator) currently 
looks like this:

dataframe$newvariable[data$oldvariable=="X"]<-"group1"

I thought this next line of code might do what I wanted, but it doesn't:

dataframe$newvariable[data$oldvariable=="X" | "Y" | "Z"]<-"group1"

I'd appreciate any suggestions. I've tried playing around with grep, but 
can't make it work.

Thanks! Mark



More information about the R-help mailing list