I am reding CSV where one columns is numeric with commas. I am using following option while reading
Prv_mnth_so <- read.csv("sales office previous month.csv", stringsAsFactors = FALSE)
then replacing commas with blank
Prv_mnth_so1$Lc_Amount <- gsub(",", "", Prv_mnth_so1$Lc_Amount)
chanfing it to numeric
Prv_mnth_so3$Lc_Amount <- as.numeric(as.character(Prv_mnth_so3$Lc_Amount))
but I get following warning
Warning message: NAs introduced by coercion
which is creating problem further in doing summary on this column
1
votes
Does any of these three posts solve your problem? 1, 2, 3
- ekoam
2 Answers
0
votes
You haven't provided an example to give you the exact answer for your data but this warning means there are some values in your data which cannot be converted to numeric.
If you have a very big data and can't manually look into your data what you could do is create a new column with numeric values and then check for values which were turned to NA. For example,
df <- data.frame(a = c("23", "34", "a", "56"))
df$b <- as.numeric(df$a)
#Warning message:
#NAs introduced by coercion
df$a[is.na(df$b)]
#[1] "a"
You can then decide what you need to do with these values.