Variable in CSV File Contains Numbers But Imported as Character

二次信任 提交于 2019-12-12 03:44:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!