[R] New Variable from Several Existing Variables

wookie1976 joe.roeschen at revecorp.com
Sat Feb 27 01:40:29 CET 2010

I am new to R, but have been using SAS for years.  In this transition period,
I am finding myself pulling my hair out to do some of the simplest things. 
An example of this is that I need to generate a new variable based on the
outcome of several existing variables in a data row.  In other words, if the
variable in all three existing columns are "Yes", then then the new variable
should also be "Yes", however if any one of the three existing variables is
a "No", then then new variable should be a "No".  I would then use that new
variable as an exclusion for data in a new or existing dataset (i.e., if
NewVariable = "No" then delete): 

Take this:
Column1, Column2, Column3
Yes, Yes, Yes
Yes, No, Yes
No, No, No
No, Yes, No
Yes, Yes, No

Generate this:
Column1, Column2, Column3, NewVariable1
Yes, Yes, Yes, Yes
Yes, No, Yes, No
No, No, No, No
No, Yes, No, No
Yes, Yes, No, No

And end up with this:
Column1, Column2, Column3, NewVariable1
Yes, Yes, Yes, Yes

Any suggestions on how to efficiently do this in either the existing or a
new dataset?

View this message in context: http://n4.nabble.com/New-Variable-from-Several-Existing-Variables-tp1571574p1571574.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list