问题与双引号和fread函数

编程入门 行业动态 更新时间:2024-10-27 05:21:50
本文介绍了问题与双引号和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函数

本文发布于:2023-08-05 11:19:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   双引号   fread

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!