Create variables in R loop
<p>I am trying to create z-scored variables based on the control group's (dx=1) mean and standard deviation. I would like to loop through all of my variables of interest (PCT:CST.L) to create these z-scores. How would i do this? Here is my data. </p>

<pre><code>X    dx    PCT  CST.R  CST.L 
1 1 Control  15  30     5
2 2 Control  20  24     22
3 3 Clinical 25  20     14
4 4 Control  17  13     12
5 5 Clinical 14  12     11
6 6 Control  13  20     15
</code></pre>

<p>And also here what I would like it to look like (well the headers, at least). </p>

<pre><code>X    dx    PCT  CST.R  CST.L  PCT_Z  CST.R_Z  CST.L_Z 
1 1 Control  15  30     5
2 2 Control  20  24     22
3 3 Clinical 25  20     14
4 4 Control  17  13     12
5 5 Clinical 14  12     11
6 6 Control  13  20     15
</code></pre>

<p>Data</p>

<pre><code>structure(list(X = 1:6, dx = c("Control", "Control", "Clinical", 
"Control", "Clinical", "Control"), PCT = c(15L, 20L, 25L, 17L, 
14L, 13L), CST.R = c(30L, 24L, 20L, 13L, 12L, 20L), CST.L = c(5L, 
22L, 14L, 12L, 11L, 15L)), .Names = c("X", "dx", "PCT", "CST.R", 
"CST.L"), class = "data.frame", row.names = c("1", "2", "3", 
"4", "5", "6"))
</code></pre>