如何让readr处理引用的NA值?

时间:2016-07-16 05:30:44

标签: r readr

library(readr)

csv <- 'x,y
"1","N/A"
"N/A","2"
'

df <- read_csv(csv, col_types = "ii", na=c("\"N/A\"", "N/A"))

运行此产生:

> df <- read_csv(csv, col_types = "ii", na=c("\"N/A\"", "N/A"))
Warning: 2 parsing failures.
row col   expected actual
  1   y an integer    N/A
  2   x an integer    N/A

实际上,"N/A"值最终为NA,但是有更优雅的方式来处理这个问题吗?例如,这没有问题,说明了所需的行为。

csv2 <- 'x,y
"1",N/A
N/A,"2"
'

df2 <- read_csv(csv2, col_types = "ii", na="N/A")  

1 个答案:

答案 0 :(得分:0)

事实证明,这是known issue已在[{1}}的(当前)开发版本中得到解决。这样做可以解决这个问题:

readr