I have a dataset that looks like this:
Var Trait Value
0 Trait1 42.26
1 Trait1 41.81
2 Trait1 41.21
0 Trait2 47.82
1 Trait2 51.44
2 Trait2 51.42
0 Trait3 10.27
1 Trait3 10.63
2 Trait3 10.14
I would like to add a forth column with normalized to 100 data calculated like this for each trait and var1:
(42.26/42.26)*100=100
(41.81/42.26)*100=98.93
(41.21/42.26)*100=97.51
For trait 2 and var1=1, Value is larger than var1=0 Value so in this case row 5 will be calculated like this: (47.82/51.44)*100=92.94
If your data is data.table:
data[, col4:= (Value/max(Value))*100, by= Trait]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With