双引号和fread函数问题

时间:2015-07-17 14:35:13

标签: r data.table

我有一些列条目如下所示:

sample.data <- data.frame(case1=c("This is just a 'shame'..."), 
                          case2="This is just a shame") # here I could not make it to insert the double quotes 
write.csv(sample.data, file="C:/sample_data.csv")

require(data.table)
test.fread <- fread("C:/sample_data.csv")
test.read.csv <- read.csv("C:/sample_data.csv")

这将在你的C:\ DRIVE上写一个文件:

csv

如果我使用fread函数(来自data.table)阅读Bumped column 79 to type character on data row 12681, field contains ' a.n."'. Coercing previously read values in this column from logical, integer or numeric back to character which may not be lossless; e.g., if '00' and '000' occurred before they will now be just '0', and there may be inconsistencies with treatment of ',,' and ',NA,' too (if they occurred in this column before the bump). If this matters please rerun and set 'colClasses' to 'character' for this column. Please note that column type detection uses the first 5 rows, the middle 5 rows and the last 5 rows, so hopefully this message should be very rare. If reporting to datatable-help, please rerun and include the output from verbose=TRUE. 数据,我会收到他的错误:

read.csv

如果我使用character,则不会发生错误,并且正确读入条目!

问题1:如何删除fread名称中的双引号。

问题2:为什么read.csv正确读取条目但{{1}}失败?

1 个答案:

答案 0 :(得分:2)

正如@Arun所建议的,目前在github上的data.table开发版本1.9.5可能对此有所帮助。

要安装,请按照此程序(需要Rtools):

# To install development version

library(devtools)
install_github("Rdatatable/data.table", build_vignettes = FALSE)

经过测试,这是为了确认最新版本的data.table可以解决双引号问题而不会出现问题。

有关详细信息和更新,请查看以下链接github data.table