I'm sure this is easy, but I'm new to R and can't find any example of the following.

Here's what I'm trying to do in pseudo-code.

data$newvar <- ifelse(data$oldvar1 == 8, 1,data$oldvar2)

In other words, if the existing variable equals 8, then the new variable should equal 1, otherwise the new variable should equal the value of another existing variable.

I've tried to follow the examples given on the web and in the R manuals, and each time I get errors or unexpected values.

Thanks

Jeff

______________________________________________
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