title: Loop through columns and add string lengths as new columns
body: <p>I have a data frame with a number of columns, and would like to output a separate column for each with the length of each row in it.</p>
  
  <p>I am trying to iterate through the column names, and for each column output a corresponding column with '_length' attached.</p>
  
  <p>For example col1 | col2 would go to col1 | col2 | col1_length | col2_length</p>
  
  <p>The code I am using is:</p>
  
  <pre><code>df &lt;- data.frame(col1 = c("abc","abcd","a","abcdefg"),col2 = c("adf qqwe","d","e","f"))
  
  for(i in names(df)){
    df$paste(i,'length',sep="_") &lt;- str_length(df$i)
   }
  </code></pre>
  
  <p>However this throws and error: </p>
  
  <blockquote>
    <p>invalid function in complex assignment.</p>
  </blockquote>
  
  <p>Am I able to use loops in this way in R?</p>