子集ffdf对象(子集vs ffwhich)

时间:2012-11-23 14:41:29

标签: r subset flat-file

我正在执行大型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   

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:3)

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