[R] R-help Digest, Vol 91, Issue 21

Marc Schwartz marc_schwartz at me.com
Tue Sep 21 22:01:30 CEST 2010


On Sep 21, 2010, at 2:47 PM, Kurt_Helf at nps.gov wrote:

> All
>     Is there a script in R equivalent to the "if then" transforms one can
> perform in Systat?  For example, I want to create a "Treatment" column
> coded either 1 or 2 for twelve field sites in a large data set.  Ideally,
> I'd be able to tell R to code sites a-f as 1 and sites g-l as 2.
> Cheers
> Kurt


Something along the lines of:

  Treatment <- ifelse(sites %in% c("a", "b", "c", "d", "e", "f"), 1, 2)

should work.  See ?"%in%" and ?ifelse

HTH,

Marc Schwartz



More information about the R-help mailing list