In the dataset “df”, I want to mark the rows as “bad’’ if any variable is missing or check=0.
df <- data.frame(col1 = c(10, 11, NA, NA, 13),
col2 = c(9, NA, NA, 7, 6), check = c(1,0,1,0,0))
if (is.na(df$col1)|is.na(df$col2)|(df$check == 0)){
df$flag = "bad"
}else{
df$flag == "good"
}
The code doesn’t work, and the warning message is:
Warning message: In if (is.na(df$col1) | is.na(df$col2) | (df$check == 0)) { : the condition has length > 1 and only the first element will be used
Aucun commentaire:
Enregistrer un commentaire