title: R: Fastest way to do row wise computation on multiple columns of a data frame
body: <p>I have a data frame where I want to add another column that's a result of computation involving 3 other columns. The method I am using right now seems to be very slow. Is there any better method to do the same. Here is the approach I am using. </p>
  
  <pre><code>library(bitops)
  
  GetRes&lt;-function(A, B, C){
    tagU &lt;- bitShiftR((A*C), 4)
    tagV &lt;- bitShiftR(B, 2)
  
    x&lt;-tagU %% 2
    y&lt;-tagV %% 4
  
    res&lt;-(2*x + y) %% 4
    return(res)
  }
  
  df &lt;- data.frame(id=letters[1:3],val0=1:3,val1=4:6,val2=7:9)
  apply(df, 1, function(x) GetRes(x[2], x[3], x[4]))
  </code></pre>
  
  <p>My data frame is very big and it's taking ages to get this computation done. Can someone suggest me to do it better?</p>
  
  <p>Thanks.</p>