title: R scale by variable and recombine to dataframe
body: <p>I'm attempting to standardize the data frame (several variables, 2 in example) by variable and recombine the data frame:</p>
  
  <pre><code>V1&lt;-c(1,2,3,4,5,6,2,3,1,2)
  V2&lt;-c(.2,.4,.3,.5,.1,.3,.6,1,0,.5)
  Size1&lt;-c("S","S","M","L","M","S","M","L","S","M")
  df&lt;-data.frame(V1,V2,Size1)
  Size1&lt;-factor(Size1)
  
  AllStand&lt;-data.frame(sapply(df[,1:2],scale),Size1=df$Size1)
  </code></pre>
  
  <p>I need to standardize by Size1. </p>
  
  <p>I tried the split-apply-combine approach</p>
  
  <p>split</p>
  
  <pre><code>splitby&lt;-split(df[,1:2],Size1)
  </code></pre>
  
  <p>apply</p>
  
  <pre><code>app&lt;-sapply(splitby,scale)
  </code></pre>
  
  <p>And here is a problem where I try to recombine it. The output is list and I need dataframe in the same format as original. I tried tapply/by/with which produce the similar lists in on step.</p>