Suppose I have the following sample data:
ID Group Score
1 A 1
2 A 3
3 A 2
4 B 5
5 B 1
6 C 1
7 C 2
8 C 4
9 D 1
10 D 3
I want to use group by with customized calculation: square root of the sum of squares of each score within each group.
- The ID is unique. (Each row is unique)
- There are 100+ groups
- The calculation is based on variable "Score"
- the # of rows in each group varies
For example, in the final output, only two columns:
Group AdjustedScore
A 3.74 **Square root of (1+9+4)
B 5.09 **Square root of (25+1)
C 4.58 **Square root of (1+4+16)
......
......
How can this be done in R? I am not good at R, thanks for any help.