An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140209/e61bcd2b/attachment.pl>
Conditional recoding for purpose of imputing
6 messages · Ana Genkova, Jim Lemon, David Winsemius +3 more
On 02/10/2014 03:03 PM, Ana Genkova wrote:
Hello, I am trying the ifelse command for imputing a variable based on a conditional statement, but the NAs do not transform. The code I am trying is: ifelse (x==1, y=="NO", y=="YES"). However, the number of NAs remains the same after the attempt. I would like to turn all Y (NAs included) into a "YES" or a "NO".
Hi Ana, What you probably want is: y<-ifelse(x==1,"NO","YES") Jim
On Feb 9, 2014, at 8:03 PM, Ana Genkova wrote:
Hello, I am trying the ifelse command for imputing a variable based on a conditional statement, but the NAs do not transform. The code I am trying is: ifelse (x==1, y=="NO", y=="YES"). However, the number of NAs remains the same after the attempt. I would like to turn all Y (NAs included) into a "YES" or a "NO".
The "==" has no place in the second and third arguments to ifelse . It should probably be: y <- ifelse (x==1, "NO", "YES") (And do note that "==" is not an assignment operator in any context.)
David Winsemius Alameda, CA, USA
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140210/99f8092b/attachment.pl>
Hello Ana, The syntax is: y <- ifelse(x==1, 'YES', 'NO') Hope this helps, Pascal
On 10 February 2014 13:03, Ana Genkova <ani.genkova at gmail.com> wrote:
Hello,
I am trying the ifelse command for imputing a variable based on a
conditional statement, but the NAs do not transform. The code I am trying
is:
ifelse (x==1, y=="NO", y=="YES"). However, the number of NAs remains the
same after the attempt. I would like to turn all Y (NAs included) into a
"YES" or a "NO".
Thanks in advance,
Ana
--
Ana Genkova
[[alternative HTML version deleted]]
______________________________________________ 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.
Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan
... Well, the syntax is corrected, but it doesn't solve her problem: ifelse() leaves NA's as NA's. "But:, you ask, "what should NA's become?" As the OP does not tell us, we are left to read tea leaves: only the Shadow knows...* Cheers, Bert * The Shadow also knows about ?is.na, which the OP should also probably read about. In fact, she would do well to read the "Introduction to R" tutorial -- or perhaps another of her choosing on the web -- where she would probably learn enough so that she wouldn't have to send posts like this in the first place! Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch
On Sun, Feb 9, 2014 at 8:52 PM, David Winsemius <dwinsemius at comcast.net> wrote:
On Feb 9, 2014, at 8:03 PM, Ana Genkova wrote:
Hello, I am trying the ifelse command for imputing a variable based on a conditional statement, but the NAs do not transform. The code I am trying is: ifelse (x==1, y=="NO", y=="YES"). However, the number of NAs remains the same after the attempt. I would like to turn all Y (NAs included) into a "YES" or a "NO".
The "==" has no place in the second and third arguments to ifelse . It should probably be: y <- ifelse (x==1, "NO", "YES") (And do note that "==" is not an assignment operator in any context.) -- David Winsemius Alameda, CA, USA
______________________________________________ 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.