title: R error when calling a function with lapply
body: <p>I have a dataset with a column composed by numbers</p>
  
  <pre><code>dati$score[10:15]
  [1]   7576   6362 764663 676164 764676   6364
  </code></pre>
  
  <p>I have this function which calculates the sums of the number in a cell which i found here on stackoverflow and works when i apply it singularly</p>
  
  <pre><code>digitsum &lt;- function(x) sum(floor(x / 10^(0:(nchar(x) - 1))) %% 10)
  </code></pre>
  
  <p>I can't apply this to the column dati$score, i get this error, i've tried using lapply and a for cycle</p>
  
  <pre><code>for (i in 1:lunghscore){
  f &lt;-  dati[i,"score"] 
  post &lt;- sum(floor(f / 18^(0:(nchar(f) - 1))) %% 18)
  dati[i,"score"] &lt;- post
  i &lt;- i + 1
  }
  </code></pre>
  
  <p>lapply</p>
  
  <pre><code>dati[,"score"] &lt;- lapply(X = dati[,"score"],FUN = digitsum)
  </code></pre>
  
  <p>I get this error</p>
  
  <pre><code>   2: In `[&lt;-.data.frame`(`*tmp*`, , "score", value = list(20, 17, 26,  :
  provided 66121 variables to replace 1 variables
  </code></pre>
  
  <p>How can i apply the function digitsum to every cell in that column?</p>