Hi all,
 
I'm handling massive data.frames and matrices in R (30000 x 400).
In the 1st column, say, I have 0s and 1s indicating rows that matter; other columns have probability values.
One simple task I would like to do would be to get the column mean values for signaled rows (the ones with 1)
As a very fresh "programmer" I have build a simple function in R which should not be very efficient indeed! It works well for current-dimension matrices, but it just not goes so well in huge ones.
 
meanprob<-function(Robj){ 
NLINE<-dim(Robj)[1];
NCOLUMN<-dim(Robj)[2];
mprob<-c(rep(0,(NCOLUMN-1)));  
for (i in 2:NCOLUMN){   
    sumprob<-0;
    pa<-0;     
    for (j in 1:NLINE){     
        if(Robj[j,1]!=0){   
            pa<-pa+1;
            sumprob<-Robj[j,i]+sumprob; 
        }
    }
    mprob[i-1]<-sumprob/pa;  
}
return(mprob);
}
 
 
So I "only" see 3 ways to get through the problem:
 
- to reformulate the function to gain efficiency;
- to establish a C-routine (for example), where loops are more "speedy", and then interfacing with R;
- to find some function/ package that already do that.
 
Can anybody illuminate my way here,
 
Mush thanks,
 
Diogo Andre' Alagador

	[[alternative HTML version deleted]]

