I\'ve got this csv table for which I need to rescale data between 0 and 1 per each column. That is, the lowest value of any given column will be 0, the highest will be 1, and al
What about using ifelse
to select the scaling direction, based on the value of variable
:
tableau.m = ddply(tableau.m, .(variable), transform,
rescale = ifelse(variable=="B",
rescale(value, to=c(1,0)), rescale(value)))
Net variable value rescale
1 a B 1.88 1.00000000
2 b B 2.05 0.32000000
3 c B 2.09 0.16000000
4 d B 2.07 0.24000000
5 e B 2.13 0.00000000
6 a C 0.15 0.00000000
7 b C 0.23 0.21621622
8 c C 0.29 0.37837838
9 d C 0.52 1.00000000
10 e C 0.30 0.40540541
11 a D 0.60 1.00000000
12 b D 0.51 0.72727273
13 c D 0.40 0.39393939
14 d D 0.36 0.27272727
15 e D 0.27 0.00000000
16 a E..e. 10.00 0.04109589
17 b E..e. 55.00 0.65753425
18 c E..e. 58.00 0.69863014
19 d E..e. 80.00 1.00000000
20 e E..e. 7.00 0.00000000
21 a F..f. 90.00 1.00000000
22 b F..f. 80.00 0.00000000
23 c F..f. 88.00 0.80000000
24 d F..f. 84.00 0.40000000
25 e F..f. 90.00 1.00000000