问题与双引号和fread函数 [英] Issue with double quotes and fread function

查看:245
本文介绍了问题与双引号和fread函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些列项如下:

  c(这只是一个耻辱... )#,因为它的字符

这将写一个文件在你的C:\ DRIVE: / p>

  sample.data<  -  data.frame(case1 = c(This is just a'shame'...) ,
case2 =这只是一个耻辱)#这里我不能让它插入双引号
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)



如果我阅读了 csv 数据 fread 函数(从data.table),我得到他的错误:

  Bumped列79在数据行12681上键入字符,字段包含'
an''。从逻辑
整数或数字后面强制此列中以前读取的值到可能不是无损的字符;例如,如果
'00'和'000'发生在它们现在只是'0'之前,并且
可能与',,的处理不一致, ',NA,'(如果他们
发生在碰撞前的这一列中)。如果这是重要的,请重新运行
并将'colClasses'设置为'字符'为此列。请注意,列
类型检测使用前5行,中间5行和
最后5行,因此希望此消息应该非常罕见。
如果向datatable-help报告,请重新运行并包含
来自verbose = TRUE的输出。

如果我使用 read.csv 发生并且条目被正确读取!



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

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

解决方案

如@Arun亲切建议, data.table 1.9.5目前在github上可能有帮助。



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

  #要安装开发版本

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

它已经过测试,因此这是为了确认 data.table 的最新版本解决了双引号的问题没有问题。



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


I have some column entries that look like this:

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

THIS WILL WRITE A FILE ON YOUR C:\ DRIVE:

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

If I read the csv data with fread function (from data.table), I get his error:

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.

If I use read.csv no error occurs and the entries are read in correctly!

Question 1: How can I remove the double quotes inside the character name.

Question 2: Why read.csv reads the entries correctly but fread fails?

解决方案

As @Arun kindly suggested, the data.table development version 1.9.5 currently on github may be of help here.

To install please follow this procedure (Rtools required):

# To install development version

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

It has been tested so this is to confirm that the newest version of data.table solves the issue with double quotes without problems.

For further details and updates check the following link github data.table

这篇关于问题与双引号和fread函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆