问题
I have a variable in a dataset (CSV format) that consists only numbers but when the dataset is imported into R, it becomes a character variable. Any reasons why?
When I tried to coerce it as numeric, a lot of NAs are introduced.
> df1$Postal_Code<-as.numeric(df1$Postal_Code)
Warning message:
NAs introduced by coercion
sum(is.na(df1$Postal_Code))
## [1] 2822
sum(is.na(as.numeric(df1$Postal_Code)))
## [1] 2837
来源:https://stackoverflow.com/questions/38449245/variable-in-csv-file-contains-numbers-but-imported-as-character