jeudi 7 mai 2020

Piping and If statement with multiple outputs in R

What am I missing here...

df <- data.frame("sn" = 1:3, "age" = c(21,15, 18), "name" = c("John","Dora", "Lynn"))

df %>% if (df$age >= 18){
  df$drive <- "yes"
  df$vote <- "yes"
}

Error in if (.) df$age >= 18 else { : 
  argument is not interpretable as logical

...in trying to make this dataframe?

  sn age name drive vote
1  1  21 John   yes  yes
2  2  15 Dora    no   no
3  3  21 Lynn   yes  yes

Aucun commentaire:

Enregistrer un commentaire