Replace NAs in a ffdf object

馋奶兔 提交于 2019-11-30 14:23:55

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/13510838/replace-nas-in-a-ffdf-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!