On 09/21/2010 09:47 PM, kurt_h...@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

Well, er, sort of.

Actually, there are multiple techniques in R to achieve the same effects
as you'd get using if statements in other languages.

e.g.

f.new <- f
levels(f.new) <- rep(1:2, each=6)

or

f.new <-f
levels(f.new) <- list("1"=letters[1:6],"2"=letters[7:12])

or

f.new <- factor(rep(1:2, each=6))[f]

or

f.new <- (as.numeric(f) > 6) + 1

or

f.new <- factor(ifelse(as.numeric(f) <= 6), 1, 2))

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to