0

i'm unable to create a new column using mutate


library(dplyr)

#View(titanic) 
titanic_clean <- na.omit(titanic) 
#View(titanic_clean) 
average_Age <- mean(titanic_clean$age) 
print(average_Age) 
titanic_clean %>% 
  mutate(titanic_age = ifelse(age < average_Age, "Below average", "above average")) 
head(titanic_clean) 
titanic_clean %>% 
  select(titanic_age) %>% 
  head(5)

i'm unable to create a new column using mutate

  • 2
    You need to assign back i.e. `titanic_clean <- titanic_clean %>% mutate(titanic_age = ifelse(age < average_Age, "Below average", "above average"))` or use the `%<>%` operator – akrun Feb 13 '23 at 06:51

0 Answers0