[R] if else statements in data frame

From: ozgrerg <ozgrgun_at_gmail.com>
Date: Sat, 16 Apr 2011 14:23:44 -0700 (PDT)


Dear R experts, I have again a problem. Let I have a data frame like below:

x y


A	A
A	B
B	B
A	B

where x and y are the column names. I want to create a new column z where it is elements
will be like that, if at each row has there at least one 'B', then z will have value of B, if not then Z will
have missing value(NA) for the corresponding row. So my result data frame should be like below:

x y Z


A	A	NA
A	B	B
B	B	B
A	B	B

How can I do this with if else statements in R. Thanks a lot.

--

View this message in context: http://r.789695.n4.nabble.com/if-else-statements-in-data-frame-tp3454646p3454646.html Sent from the R help mailing list archive at Nabble.com.



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. Received on Sat 16 Apr 2011 - 23:54:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Apr 2011 - 08:20:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive