Is there a way to speed-up the following R code?
actionVec<-NULL
for(iii in 1:length(resultTable$V1)){
actionVec[iii]<- sum(browse$V2==resultTable$V1[iii] & browse$V4 == i & browse$V5 == ii)}
this is a loop to form a vector for each record (row) in resultTable, containing the number of entries that match the conditions in table browse
this script runs 36 minutes. I suspect that there is a way to make it run much faster. I have experienced a reduction from 15 min to 10 ms (!) on another script when avoiding loops but using vectors. But in this case I can`t find out how to make it.
EDIT1: variables i and ii come from outer loop and may be two arbitrary integers for this loop.
EDIT2: more complete version
SESSION_NUMBER<-length(resultTable$V1)
for(i in 1:55){ for(ii in 1:21){
if(sum(browse$V4 == i & browse$V5 == ii) > treshold){
actionVec<-NULL
for(iii in 1:SESSION_NUMBER){
actionVec[iii]<- sum(browse$V2==resultTable$V1[iii] & browse$V4 == i & browse$V5 == ii)}
resultTable[,i+1] <- actionVec
}}}