Is there a way to speed-up the following code?
Yes, there is:

Since i and ii and browse$V4 and browse$V5 are outside of the loop, you can precalculate this before going into the loop. That way you can save a small bit of calculating.

if (sum(browse$V4 == i &amp; browse$V5 == ii) &gt; treshold)

I dunno what you're doing here, but from what I can see, you're calling sum(1) or sum(0). Naturally, this produces 0 or 1. Then you're comparing it to treshold. Well, if treshold is below 1 but not below 0, then you can just remove the check, as well as the for loop, since browse doesn't change in the for loop!

If treshold is below 0, then the check is not needed. Thus, (please check if my syntax is correct)

SESSION_NUMBER&lt;-length(resultTable$V1)

if(treshold &lt; 1 &amp;&amp; treshold &gt;= 0){
    //check if browse$V4 and browse$V5 are in range
    if(browse$V4 &gt;= 1 &amp;&amp; browse$V4 &lt;= 55 &amp;&amp; browse$V5 &gt;= 1 &amp;&amp; browse$V5 &lt;= 21){
        actionVec&lt;-NULL
        for(iii in 1:SESSION_NUMBER){
            actionVec[iii]&lt;- sum(browse$V2==resultTable$V1[iii])
        }
        resultTable[,browse$V4+1] &lt;- actionVec
    }
} else if (treshold &lt; 0){
    for(i in 1:55){ 
        for(ii in 1:21){  
            actionVec&lt;-NULL
            temp&lt;-browse$V4 == i &amp; browse$V5 == ii
            for(iii in 1:SESSION_NUMBER){
                actionVec[iii]&lt;- sum(browse$V2==resultTable$V1[iii] &amp; temp)
            }
            resultTable[,i+1] &lt;- actionVec
        }
    } 
}