2

我正在使用在某些列中具有 NA 的 ffdf 对象。NA 是使用merge.ffdf进行左外部合并的结果。我想用 0 替换 NA,但无法做到。这是我正在运行的代码:

    library(ffbase)
    deals <- merge(deals,rk,by.x=c("DEALID","STICHTAG"),by.y=c("ID","STICHTAG"),all.x=TRUE)
    attributes(deals)
    $names
    [1] "virtual"   "physical"  "row.names"
    $class
    [1] "ffdf"

vmode(deals$CREDIT_R)
[1] "double"

    idx <- ffwhich(deals,is.na(CREDIT_R)) # CREDIT_R is one of the columns with NAs
    deals.strom[idx,"CREDIT_R"]<-0
    error in `[<-.ffdf`(`*tmp*`, idx, "CREDIT_R", value = 0) : 
      ff/ffdf-iness of value and selected columns don't match

知道我做错了什么吗?一般来说,我想了解更多关于替换 ff 和 ffdf 类的方法。有什么建议可以让我找到有关该主题的一些示例吗?

4

1 回答 1

4

ff 包的手册中指出了一个名为 ffindexset 的函数。

idx <- is.na(deals$CREDIT_R) ## This uses is.na.ff_vector from ffbase
idx <- ffwhich(idx, idx == TRUE) ## Is part of ffbase
deals$CREDIT_R <- ffindexset(x=deals$CREDIT_R, index=idx, value=ff(0, length=length(idx), vmode = "double")) ## Is part of ff
deals$CREDIT_R[idx] <- ff(0, length=length(idx), vmode = "double") ## this one will probably also work

也看看 ?Extract.ff

于 2012-11-22T10:51:58.447 回答