r - 双引号和 fread 函数的问题

标签 r data.table

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

c("This is just a "shame"...") # since its a character

这将在您的 C:\驱动器上写入一个文件:

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

如果我使用 fread 函数(来自 data.table)读取 csv 数据,我会得到他的错误:

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,则不会发生错误,并且条目会正确读取!

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

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

最佳答案

正如 @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

关于r - 双引号和 fread 函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31478316/

相关文章:

r - 三个数据表合并行为不一致

r - 在 Shiny 的应用程序中嵌入 Google 分析跟踪代码

r - 将有图例的图与没有图例的图结合起来

r - 将满足所有可能条件的条件的所有值相加

r - 按组有条件NA填充

R 提高功能的性能

r - 使用不等式表达式的内连接

r - R CMD build 和 R CMD INSTALL --build in R 之间的区别

r - 查找向量的相似元素并修改其间的所有内容

r - 条件(不等式)加入 data.table