2013-08-21 22 views
1

我正在處理一個大型的數據集(3.5M行和40列),我需要清除一些值,這樣我才能夠計算其他參數,當我開始制定時數據模型。對ffdf對象的數據幀進行計算

問題是,它一直在使用我一直在使用的for循環,因此我想嘗試使用ff軟件包。數據框被稱爲數據,它由銀行的大量客戶信息組成。它被導入爲.csv文件。我需要做的是去除所有的客戶(標記序列),如果他們AverageStanding變量是有史以來負

> ffd<-as.ffdf(data) 
> lastserial = tail(ffd$Serial,1) 
> for(k in 1:lastserial){ 
+ tempvecWith <- vector() 
+ tempvecWith <- ffd[ffd$Serial==k, ]$AverageStanding 
+ if(any(tempvecWith < 0)){ 
+  ffd_clean<- ffd[!ffd$Serial ==k, ] 
+ } 
+ } 

這是我收到的錯誤:

Error in as.hi.integer(x, maxindex = maxindex, dim = dim, vw = vw, pack = pack) : 
NAs in as.hi.integer 

我如何能避免任何想法這些錯誤?

回答

1

錯誤來自於這部分代碼ffd[ffd$Serial==k, ]。即ffd$Serial==k返回一個ff邏輯向量。但是,如果您想要索引或子集ff向量或ffdf,則需要提供索引編號,而不是邏輯向量。你可以通過使用ffbase包中的ff來將你的ff向量變成一個索引號的ff向量。所以對於你的問題,我相信你正在尋找這種類型的代碼(沒有測試,因爲你沒有提供任何數據)。

require(ffbase) 
idx <- ffd$AverageStanding < 0 
idx <- ffwhich(idx, idx==TRUE) 
open(ffd) 
serials.with.negative <- ffd$Serial[idx] 
serials.with.negative <- unique(serials.with.negative) 
ffd$is.customer.with.negative.avgstanding <- ffd$Serial %in% serials.with.negative 

idx <- ffd$is.customer.with.negative.avgstanding == FALSE 
idx <- ffwhich(idx, idx==TRUE) 
open(ffd) 
ffd_clean <- ffd[idx, ]