mardi 21 juillet 2020

Using an if statement to modify data in a column in R

I have data that looks like this:

Person Change
1       10 
2       0.5
3       -0.25
4       5
5       -20

I want to say that if Change < 1, then multiply the number in this column by 100. The results I am expecting to see are.

Person Change
1       10 
2       50
3       -25
4       5
5       -20

I have tried an if formula saying

if(df$Change <1 && df$Change > 0 {
df$Change*100
}

This runs fine but does not make any changes to the data and I am unsure of what else to try.

Aucun commentaire:

Enregistrer un commentaire