title: R: Apply function on specific columns preserving the rest of the dataframe
body: <p>I'd like to learn how to apply functions on specific columns of my dataframe without "excluding" the other columns from my df. For example i'd like to multiply some specific columns by 1000 and leave the other ones as they are. </p>
  
  <p>Using the sapply function  for example like this:</p>
  
  <pre><code>    a&lt;-as.data.frame(sapply(table.xy[,1], function(x){x*1000}))
  </code></pre>
  
  <p>I get new dataframes with the first column multiplied by 1000 but without the other columns that I didn't use in the operation. So my attempt was to do it like this:</p>
  
  <pre><code>    a&lt;-as.data.frame(sapply(table.xy, function(x) if (colnames=="columnA") {x/1000} else {x}))
  </code></pre>
  
  <p>but this one didn't work. </p>
  
  <p>My workaround was to give both dataframes another row with IDs and later on merge the old dataframe with the newly created to get a complete one. But I think there must be a better solution. Isn't it? </p>