 <p>You can use <code>outer</code> with a vectorized version of your function using <code>mapply</code>.</p> <pre><code>id &lt;- seq_along(colnames(ddf)) outer(id,id,function(x,y)mapply(myfunction,ddf[,x],ddf[,y])) </code></pre>