【发布时间】:2015-07-17 14:35:13
【问题描述】:
我有一些如下所示的列条目:
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:如何删除 character 名称中的双引号。
问题 2:为什么 read.csv 可以正确读取条目但 fread 失败?
【问题讨论】:
-
谢谢,但我正在读取的数据中有随机名称和多个条目,所以不能只是逃避条目。
-
一般在 R
"中引用单引号,反之亦然。 -
见here
-
@Michael:谢谢,它似乎解释了一切。不过,我必须检查我的数据。
-
@Maximilian,您可以自己回答并接受它,以便对可能遇到此问题的其他人有用..(直到 1.9.5 作为 1.9.6 推送到 CRAN)。
标签: r data.table