0

I have a very large ffdf named 'Scenarios' and I would like to sort one of the columns named 'Eventfreq' into bins based on two variables and then take the sum of the values within each BIN.

The function below essentially does this for one set of variables:

Disag <- function(M,R1,R2){
  x<-sum.ff(Scenarios[ffwhich(Scenarios,Magnitude==M & Rjb>R1 & Rjb<R2),]$Eventfreq)
  return(x)
}  

Now I just want to apply the above function but vary the 3 input variables (M, R1, R2), I have tried a loop as follows:

M<-seq(4.55, 6.45, by=0.1) #First BIN Variable
R1<-seq(2, 16, by=1)  #Second BIN Variable lower limit 
BINS<-expand.grid(R1,M)   #Create all the different BINS
colnames(BINS)<-c("R1", "Mag")
BINS$R2<-with(BINS,R1+0.1)   #Second BIN Variable upper limit 

Z = (rep(NA,nrow(BINS)))
for(i in 1:nrow(BINS)){
  Z[i]=Disag(BINS$Mag[i],BINS$R1[i], BINS$R2[i])
}

But then I get an error message as follows:

Error in UseMethod("as.hi") : 
  no applicable method for 'as.hi' applied to an object of class "NULL" 

The function works fine when I manually input the variables M, R1, R2, so the problem must be with how the loop is operating, any suggestions would be appreciated. Thanks

user3565975
  • 75
  • 2
  • 9
  • Probably ffwhich return NULL, meaning there is nothing in your selection. But you need to make the example reproducible before we can check. –  Jun 04 '14 at 08:08
  • You were correct, I have solved the problem as follows, let me know what you think: – user3565975 Jun 04 '14 at 17:39

0 Answers0