简体   繁体   中英

Replace NAs in a ffdf object

I`m working with a ffdf object which has NAs in some of the columns. The NAs are the result of a left outer merge using merge.ffdf .I would like to replace the NAs with 0s but not managing to do it. Here is the code I am running:

    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

Any idea what I am doing wrong? In general I would like to learn more about replacing methods for class ff and ffdf. Any suggestion where I can find some examples about the topic?

The manual of package ff indicates a function called 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

Also have a look at ?Extract.ff

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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