title: lapply on single column in data frame
body: <p>I have a data frame which I populate from a csv file as follows (<strong>data for sample only</strong>) :</p>
  
  <pre><code>&gt; csv_data &lt;- read.csv('test.csv')
  &gt; csv_data
    gender country income
  1      1      20  10000
  2      2      20  12000
  3      2      23   3000
  </code></pre>
  
  <p>I want to convert country to factor. However when I do the following, it fails :</p>
  
  <pre><code>&gt; csv_data[,2] &lt;- lapply(csv_data[,2], factor)
  Warning message:
  In `[&lt;-.data.frame`(`*tmp*`, , 2, value = list(1L, 1L, 1L)) :
  provided 3 variables to replace 1 variables
  </code></pre>
  
  <p>However, if I convert both gender and country to factor, it succeeds :</p>
  
  <pre><code>&gt; csv_data[,1:2] &lt;- lapply(csv_data[,1:2], factor)
  &gt; is.factor(csv_data[,1])
  [1] TRUE
  &gt; is.factor(csv_data[,2])
  [1] TRUE
  </code></pre>
  
  <p>Is there something I am doing wrong? I want to use lapply since I want to programmatically convert the columns into factors and it could be possible that the number of columns to be converted is only 1(it could be more as well, this number is driven from arguments to a function). Any way I can do it using lapply only?</p>