 <p>Try this:</p> <pre><code>#data df &lt;- read.table(text=" tissueA tissueB tissueC gene1 4.5 6.2 5.8 gene2 3.2 4.7 6.6") #result apply(df,1,function(i){ my.max &lt;- max(i) my.statistic &lt;- (1-log2(i)/log2(my.max)) my.sum &lt;- sum(my.statistic) my.answer &lt;- my.sum/(length(i)-1) my.answer }) #result # gene1 gene2 # 0.1060983 0.2817665 </code></pre>