繁体   English   中英

函数ff:read.csv.ffdf中的colClasses参数的当前状态(ff-R程序包)

[英]Current status of colClasses argument in function ff:read.csv.ffdf (ff - R package)

由于以下代码中的参数colClasses=c("id"="character") ,错误colClasses=c("id"="character") vmode 'character' not implemented

df <- read.csv.ffdf('TenGBsample.csv',
      colClasses=c("id"="character"), VERBOSE=TRUE)

read.table.ffdf 1..1000(1000)csv-read = 0.02sec ff中的错误(initdata = initdata,length = length,levels = level,ordered = ordered,:
vmode“字符”未实现

其中TenGBsample.csv中的第一TenGBsample.csv 'id',由30位数字组成,超过了我的64位系统(Windows)上的最大数字,我想将它们作为字符进行处理,第二列包含小数字,因此无需调整。

我已经检查过,并且有vmode “字符”模式: http : //127.0.0.1 : vmode / vmode.html

请注意help(read.csv.ffdf)的以下内容

... read.table.ffdf行为设计得尽可能类似于read.table 但是,请注意以下差异:

  1. 不支持字符向量 ,必须将字符数据读取为以下colClasses之一:'Date','POSIXct','factor,'ordered'。 默认情况下,字符列被视为因素。 因此,不允许使用参数“ as.is”和“ stringsAsFactors”。

因此,您无法读取字符中的值。 但是,如果文件中的id列已具有数字值,则可以将它们读取为双精度,然后重新格式化。 format(x, scientific = FALSE)将以标准符号打印x

这是一个数据集x的示例,其中id是数字,具有30位数字。

library(ff)

x <- data.frame(
    id = (267^12 + (102:106)^12),  
    other = paste0(LETTERS[1:5],letters[1:5])
)
## create a csv file with 'x'
csvfile <- tempPathFile(path = getOption("fftempdir"), extension = "csv")
write.csv(
    format(x, scientific = FALSE), 
    file = csvfile, row.names = FALSE, quote = 2
)    
## read in the data without colClasses
ffx <- read.csv.ffdf(file = csvfile)
vmode(ffx)
#       id     other 
# "double" "integer" 

现在,我们可以强制ffx使用ffx[,]data.frame进行ffx[,]并重新设置id列的格式。

df <- within(ffx[,], id <- format(id, scientific = FALSE))
class(df$id)
# [1] "character"
df
#                               id other
# 1 131262095302921040298042720256    Aa
# 2 131262252822013319483345600512    Bb
# 3 131262428093345052649582493696    Cc
# 4 131262622917452503293152460800    Dd
# 5 131262839257598318815163187200    Ee

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM