mercredi 6 mai 2020

ifelse in a mutate function in r

I am trying to add a column with a condition using the mutate function in r, but keep getting an error. The code is straight from the teacher's lecture, but yet an error occurs. The LineItem column is a factor class, I am not sure if that make a difference. Please advice on what I am missing.

Thank you, Avi

df <- read.csv('ities_short.csv')

colSums(is.na(df))

sl <- str_length(df$LineItem)
avg <- mean(str_length(df$LineItem))

df <- df %>% mutate(LineItem_LongName = ifelse(sl > avg), 1, 0)

Error in ifelse(sl > avg) : argument "yes" is missing, with no default

Aucun commentaire:

Enregistrer un commentaire