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")