本文介绍了替换ffdf对象中的NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用在某些列中具有NA的ffdf对象. NA是使用 merge.ffdf 进行左外部合并的结果.我想将NA替换为0,但无法做到这一点.这是我正在运行的代码:
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
知道我在做什么错吗?总的来说,我想了解更多有关替换ff和ffdf类的方法的信息.在哪里可以找到有关该主题的示例的任何建议?
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?
推荐答案
ff软件包的手册指出了一个称为ffindexset的函数.
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
还可以看看?Extract.ff
Also have a look at ?Extract.ff
这篇关于替换ffdf对象中的NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!