I am trying to write a line of code in R to create a variable consisting of strings corresponding to the value of another variable.
batting$spray <- with(batting, (if(Pull > 120){
"Pull"
} else {
"Neutral"
}
The goal of this is for each data point, the variable spray will be "Pull" if Pull > 120 or "Neutral" otherwise.
However, this code is returning an error.
Warning message:
In if (Pull > 120) { :
the condition has length > 1 and only the first element will be used
How should I approach fixing this?
Aucun commentaire:
Enregistrer un commentaire