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