0

I am trying to assign labels to ggplot2 outliers the way it is specified here:

Labeling Outliers of Boxplots in R

And to create a new outlier column I am using the following code:

splitData %>% 
  group_by(Sample.group) %>%
  mutate(outlier=ifelse(is_outlier(value), value, as.numeric(NA)))

And I am getting the error:

Error in mutate_impl(.data, dots) : Evaluation error: missing values and NaN's not allowed if 'na.rm' is FALSE.

The splitData looks like that:

enter image description here

I guess, wrong as.numeric() happens somewhere; there is a similar thread:

Error: missing values and NaN's not allowed if 'na.rm' is FALSE

But I am having trouble figuring out where. Any suggestions would be greatly appreciated.

Nikita Vlasenko
  • 4,004
  • 7
  • 47
  • 87
  • Please share your data using `dput()`. Seem more here: [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/) – Tung Apr 24 '18 at 22:46

1 Answers1

2

You cannot turn NA values into a number by using as.numeric(NA). You should omit the NA values or impute them if you can. Missing values are always a nuisance but sometimes there is nothing more left to do than dropping the samples (=rows in your case).

Jens
  • 2,363
  • 3
  • 28
  • 44
  • Okay, I saw the example for the boxplots (mtcars) and there it is used to add NA to a non-factor column (dbl formatted) during the ifelse statement. But did you source the function is_outlier? `is_outlier <- function(x) { return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x)) }` – Jens Jul 05 '18 at 11:49