[R] ifelse help

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Jul 11 04:55:31 CEST 2012


You failed to tell us any of: the actual code you used, the data you were working with, or the actual error you got. Your "pseudo-code" looks okay to me, so I suggest you read the Posting Guide and try again. (Anything other than a complete reproducible example of your problem is unlikely to elicit useful responses. Pseudo-code is definitely "other".)
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Jeff <r at jp.pair.com> wrote:

>
>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 at 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.



More information about the R-help mailing list