title: dim(X) must have a positive length when applying function in data frame
body: <p>I'm trying to apply this function to a data frame column:</p>
  
  <pre><code>best_recom &lt;- function(x,n=1) {
     y &lt;- result2[x,order(-result2[x,])[n]]
     inds = which(result2[x,] == y, arr.ind=TRUE)
     recom &lt;- names(inds[1])
    return(recom)
  }
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>apply(last_visit[,2], 1, best_recom)
  </code></pre>
  
  <p>But I'm getting this error:</p>
  
  <pre><code>dim(X) must have a positive length
  </code></pre>
  
  <p>I already tried applying it as a matrix like this:</p>
  
  <pre><code>apply(as.matrix(last_visit)[,2],1,recomenda_n_melhor)
  </code></pre>
  
  <p>But I get the same error.
  These are the data frames that are used:</p>
  
  <p>result2 - a similarity matrix - this is just a sample</p>
  
  <pre><code>          X1.0      X1.1      X2.1      X3.1
  X1.0     0.0000000 0.5000000 0.3872983 0.3162278
  X1.1     0.5000000 0.0000000 0.2581989 0.0000000
  X2.1     0.3872983 0.2581989 0.0000000 0.0000000
  X3.1     0.3162278 0.0000000 0.0000000 0.0000000
  </code></pre>
  
  <p>last_visit </p>
  
  <pre><code>  customer  cat
  1        1 X5.1
  2        2 X6.1
  3        3 X1.1
  4        4 X2.1
  </code></pre>