What's the best way to replace missing values with NA when reading in a .csv?

痴心易碎 提交于 2019-12-02 18:25:14

The <NA> vs NA just means that some of your columns are character and some are numeric, that's all. Absolutely nothing is wrong with that.

As Ben mentioned above, if some of your missing values in the csv are represented by a single period, ., then you can specify a vector of values that should be treated as NAs via:

na.strings=c("",".","NA")

as an argument to read.csv.

You can also use the more flexible readr package, whose equivalent function and argument are read_csv() and na.

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