mercredi 25 août 2021

R: Nested If Statements

Is this the correct way to write IF statements in R?

New$var = ifelse(new$var1 < 10, "a", ifelse (new$var1>10 & new$var1<20, "b", ifelse(new$var1>20 & new$var1 <30, "c", "d")))

I wrote the following code and found values of "var" that should be in "a" are actually in "d". "Var1" has no negative values.

But for some reason, when I use the which statement, the code seems to run fine.

How is this possible

Thanks

Aucun commentaire:

Enregistrer un commentaire