I want to create a new variable "influence" in my dataset (f) based on several conditions taking into account other variables. Here is my code:
f$influence <- if (f$ApportLysine_gj <= f$LysBesoinPlus5 & f$ApportLysine_gj >= f$LysBesoinMoins5){f$influence = 1} else if (f$ApportLysine_gj > f$LysBesoinPlus5 & f$ApportLysine_gj < f$LysExces20){f$influence = 2} else if (f$ApportLysine_gj >= f$LysExces20) {f$influence = 3} else if (f$ApportLysine_gj < f$LysBesoinMoins5 & f$ApportLysine_gj > f$LysDeficit20){f$influence = 4} else {f$influence = 5}
I only get an error message "argument is of length zero". What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire