Standardize data columns in R in subgrups
<p>I'm struggling with standardization of data columns in R in subgroups.</p>

<p>I created the data frame:</p>

<pre><code>df&lt;-data.frame(
salesPerson=sample(c('Alan','Bob','Cindy'),20 ,replace=TRUE)
, quater=sample(c('Q1','Q2','Q3'),20 ,replace=TRUE) 
,salesValue=runif(20, 5.0, 7.5)
)
</code></pre>

<p>I would like to add additional column to the data frame with scaled values of Sales. </p>

<p>To scale all column I can use code:</p>

<pre><code>df$salesValueScaled&lt;-scale(df$salesValue)
</code></pre>

<p>The problem is that I would like to scale sales separably for each combination of columns salesPerson and quater. Sth like: </p>

<pre><code>df$salesValueScaled&lt;-scale(df$salesValue, by =c(df$salesPerson,df$quater))
</code></pre>

<p>I have been searching for this solution on this forum but I couldn't find a solution to this problem.</p>

<p>Thank you in advance for help.</p>