title: Use sample() function to apply in a range of column
body: <p>I have a data.frame called "prob" with 3 columns of probabilities.</p>
  
  <pre><code>              A              B         C
  
  1         0.346          0.629     0.026
  
  2         0.377          0.529     0.094
  
  3         0.454          0.495     0.051
  
  4         0.338          0.604     0.058
  
  5         0.616          0.331     0.054
  </code></pre>
  
  <p>I want to sample one item from (A,B,C) in each row. So I apply the following function:</p>
  
  <pre><code>sapply(prob[,2:5], 
         function(p) sample(x = c(0:2), size = 1, prob = p))
  </code></pre>
  
  <p>R returns an error:  </p>
  
  <blockquote>
    <p>Error in sample.int(length(x), size, replace, prob) :    incorrect
    number of probabilities</p>
  </blockquote>
  
  <p>How can I solve this? Thanks!</p>