r - datatable.integer64 参数对我不起作用应该吗?

标签 r data.table long-integer read.csv

我正在尝试将 integer64 加载为 fread 中的 character ?fread 表明 integer64 参数未实现,但 options(datatable.integer64) 已实现。尽管 fread 一直以 int64 的形式加载。

我如何告诉fread加载为字符编辑 [如果colClasses是答案,我认为它不允许指定单个列名或索引,并且我加载的表有数十列,所以不切实际...... =>这是错误的]

这是一个示例

#for int 64
library(bit64)
#for fast everything
library(data.table)

#here is a sample
df <- structure(list(IDFD = structure(c(5.13878419797985e-299, 5.13878419797985e-299, 
+ 5.13878419797985e-299, 5.13878419797987e-299, 5.13878419797987e-299, 
+ 5.13878419797987e-299, 5.13878419797987e-299, 5.13878419797987e-299, 
+ 5.13878419797988e-299, 5.13878419797988e-299), class = "integer64")), .Names = "IDFD", row.names = c(NA, 
+ -10L), class = c("data.table", "data.frame"))
#write the sample to file
write.csv(df,"test.csv",quote=F,row.names=F)

#I can't load it as characters
options(datatable.integer64='character')
str(fread("test.csv",integer64='character'))
Classes ‘data.table’ and 'data.frame':  10 obs. of  1 variable:
 $ IDFD:Class 'integer64'  num [1:10] 5.14e-299 5.14e-299 5.14e-299 5.14e-299 5.14e-299 ...

最佳答案

这已在 R-Forge 上的 v1.8.11 中实现,但尚未在 CRAN 上实现。来自 NEWS :

o fread's integer64 argument implemented. Allows reading of integer64 data as 'double' or 'character' instead of bit64::integer64 (which remains the default as before). Thanks to Chris Neff for the suggestion. The default can be changed globally; e.g, options(datatable.integer64="character")

关于:

If colClasses is the answer, I think it does not allow to specify a single column name or index and the table I load has tens of columns so unpracticable...

fread 中的

colClasses 确实允许您覆盖一列或几列的类型(按名称或数字),其余的将被自动检测。正是出于您所说的原因。如果没有,请报告为错误。 colClasses 的替代方案是 datatable.integer64 全局选项,它可以让您告诉 fread,每当它检测到 integer64 时,它都应该将其加载为字符或 double (也在 v1.8.11 中)。

关于r - datatable.integer64 参数对我不起作用应该吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18718045/

相关文章:

regex - 在 R 中使用 grepl 完成单词匹配

C 编译器无法识别 unsigned long

java - 为什么循环不将 long 作为其条件中的有效类型?

r - sum 和 + 之间的不同输出

r - 从 r 中的名称列表中提取前两个字符

r - testthat:处理警告和值

AWS 上的 R 和 data.table

R data.table fread - 读取列作为日期

r - data.table对象分配了:= from within function not printed

c - 如何在 Cython 中使用 128 位整数