mardi 28 mars 2017

Using conditional If/else statements and Mutate [duplicate]

This question already has an answer here:

I would like to create a new variable based on an if/else statement. Pretty much I need to run a calculation for a new variable, but the calculation is different for men vs women. I know how to write the code using mutate to get a new column using the calculation, but am having a hard time creating a conditional statement based on sex. Here is what I have so far:

This is just applying the calculation to men and women:

test2 <- mutate(test, FEV1 = 443 - (30*Age) + (23*Height))

This is what I would like to do (I know it's not correct)

test2 <- mutate(test, FEV1 = ifelse( Sex ==1, *equation1*, *equation2*))

Thanks in advance for any help!

Aucun commentaire:

Enregistrer un commentaire