Hi everyone,
I am struggling with this code right now. There are missing values in my data (NA) and I don't know how to fix the code to accommodate the fact that there are missing values. Thank you in advance!
This is the code:
mydata %>%
mutate(outlier=ifelse(is_outlier(selfesteem),selfesteem,as.numeric(NA))) %>%
ggplot(.,aes(x="", y=selfesteem))+
geom_boxplot()+
theme_classic()+
geom_text(aes(label=outlier),na.rm = TRUE, hjust=-.3)+
xlab("Information")+ ylab("Selfesteem rating")+
labs(title="Average rating of selfesteem")
It is telling me that:
Error: Problem with mutate() column outlier. outlier = ifelse(is_outlier(ovcompt), ovcompt, as.numeric(NA)).
x missing values and NaN's not allowed if 'na.rm' is FALSE
Run rlang::last_error() to see where the error occurred.
I think you might have found the solution. You might also consider using "if_else" rather than "ifelse". Both work, but "if_else" is more consistent within the tidyverse and usually faster. See Vectorised if — if_else • dplyr (tidyverse.org) for more information.