当csv中有字符时如何使用R填充

How to use fill when there are characters in csv with R

例如我有以下 table.csv:

    ,title1   ,title2
f1   ,2     ,5
f2   ,3     ,"8s"
f3   ,8     ,13
f4   ,"21,4"  ,"19,4"
f5   ,16     ,12
f6   ,12

我什么时候使用

read.csv(file=file.choose(),header = T,sep = ",",quote = "\"",row.names=1,fill = TRUE,dec = ",")
#---> fill = T

生成但填充 = T 无效

      title1 title2
f1      13.0     10
f2      11.0     8s
f3      18.0     13
f4      21.4   19,4
f5      16.0     12
f6      12.0   

嗯,我的问题是由 8s 产生的,它 不允许用 NA 填充。 有解决办法吗?

通过指定 na.strings,它会将空白读作 NA

read.csv(file.choose(), header = TRUE, sep=",", quote = "\"", 
          row.names = 1, fill = TRUE, dec = ",", na.strings = "")
#      title1 title2
#f1       2.0      5
#f2       3.0     8s
#f3       8.0     13
#f4      21.4   19,4
#f5      16.0     12
#f6      12.0   <NA>