Returning an existing data frame with four new columns
Here's a faster way:

add_2maxFaster &lt;- function(x)
{
  imax1 &lt;- which.max(x)
  imax2 &lt;- which.max(x[-imax1])
  if (imax2 &gt;= imax1) imax2 &lt;- imax2 + 1L
  c(x, x[imax1], x[imax2], imax1, imax2) 
}

set.seed(42)
m &lt;- matrix(runif(1e6), 1e4)

# Compare speed:
system.time( a1&lt;-apply(m, 1, add_2max) )        # 0.38 secs
system.time( a2&lt;-apply(m, 1, add_2maxFaster) )  # 0.15 secs

# ...And compare results
all.equal(a1,a2) # TRUE