mercredi 26 juillet 2017

Mutate multiple columns with a certain condition in R

I have this data

M1  M2  M3 UCL
1   2   3   1.5

I would like to make new columns with this condition:

If M1 is more than UCL, MM1 will be "UP" and otherwise "NULL"

If M2 is more than UCL, MM2 will be "UP" and otherwise "NULL"

If M3 is more than UCL, MM3 will be "UP" and otherwise "NULL"

M1  M2  M3 UCL   | MM1  MM2 MM3
1   2   3   1.5  | NULL UP  UP

But I have several M column (like M1~M1005) so that I would like to make some code such as mutate_each and mutate_at. How do I use the function using mutate and ifelse in order to make new columns under a particular condition?

Aucun commentaire:

Enregistrer un commentaire