The problem:
I have a tibble column that I wish to convert to a numeric column. Most of the cells can be converted easily (i.e. "1" becomes 1, "NA" becomes NA). Some however cannot be converted easily (e.g. "1-4"), in these cases I am understandably given a "NAs introduced by coercion" error.
Is there a simple way or function (preferably in tidyverse style/syntax) that can show the rows that which were not easily converted to numeric.
Reproducible example:
tibble::tibble(x = 1:10,
y = c("11", "12", "13", "14", "15", "16", "17", "18-21", "22", "23")) %>%
dplyr::mutate(y = as.numeric(y))
The output I looking for in this case is:
| x | y | |
|---|---|---|
| 8 | 8 | "18-21" |