[R] ifelse help

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Wed Jul 11 03:23:46 CEST 2012


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jeff
> Sent: Tuesday, July 10, 2012 5:26 PM
> To: r-help
> Subject: [R] ifelse help
> 
> 
> 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
> 

Rather than tell us that you tried some examples and they didn't work, show us what you tried (i.e. a reproducible example as requested in the posting guide) so that we can play along at home. :-)  

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204




More information about the R-help mailing list