我正在使用ffdf对象,该对象在某些列中具有NA。 NAs是使用 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方法的知识。有什么建议可以找到关于这个主题的一些例子吗?
答案 0 :(得分: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