 <p>In order to put the result from your <code>apply()</code> call into a data frame, you could do</p> <pre><code>df &lt;- data.frame(id=data$id, largest_value_var=apply(data[,-1], 1, function(x) names(x)[which.max(x)])) </code></pre> <p>Note that <code>c(names(x))</code> is the same as <code>names(x)</code>, so I omitted <code>c()</code>.</p>