gpt4 book ai didi

r - 子集 ffdf 对象(子集 vs ffwhich)

转载 作者:行者123 更新时间:2023-12-04 12:17:53 28 4
gpt4 key购买 nike

我正在执行大型 ffdf 对象的子集,我注意到当我使用 subset.ff 时,它会生成大量 NA。我通过使用 ffwhich 尝试了另一种方法,结果要快得多,并且没有生成 NA。这是我的测试:

library(ffbase)
# deals is the ffdf I would like to subset
unique(deals$COMMODITY)
ff (open) integer length=7 (7) levels: CASH CO2 COAL ELEC GAS GCERT OIL
[1] [2] [3] [4] [5] [6] [7]
CASH CO2 COAL ELEC GAS GCERT OIL

# Using subset.ff
started.at=proc.time()
deals0 <- subset.ff(deals,deals$COMMODITY %in% c("CASH","COAL","CO2","ELEC","GCERT"))
cat("Finished in",timetaken(started.at),"\n")
Finished in 12.640sec
# NAs are generated
unique(deals0$COMMODITY)
ff (open) integer length=8 (8) levels: CASH CO2 COAL ELEC GAS GCERT OIL <NA>
[1] [2] [3] [4] [5] [6] [7] [8]
CASH CO2 COAL ELEC GAS GCERT OIL NA

# Subset using ffwhich
started.at=proc.time()
idx <- ffwhich(deals,COMMODITY %in% c("CASH","COAL","CO2","ELEC","GCERT"))
deals1 <- deals[idx,]
cat("Finished in",timetaken(started.at),"\n")
Finished in 3.130sec
# No NAs are generated
unique(deals1$COMMODITY)
ff (open) integer length=7 (7) levels: CASH CO2 COAL ELEC GAS GCERT OIL
[1] [2] [3] [4] [5] [6] [7]
CASH CO2 COAL ELEC GAS GCERT OIL

知道为什么会这样吗?

最佳答案

subset.ff可能正在使用 [和您的标准,但不包括 !is.na(.)条款。 “[”的默认值是返回标准向量的 TRUE 或 NA 项。正则子集函数添加一个 !is.na(.)条款,但也许 ffbase 的作者没有解决这个问题。

关于r - 子集 ffdf 对象(子集 vs ffwhich),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13531265/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com