df <- data.frame(x=c(1,1,2,2,3,3,3),y=c(1,3,4,3,5,2,3))
I'd to create a column with the scaled values of y for each element of x
so when x==1 --> scale(c(1,3)), x==2 --> scale(4,3), etc
This is what I'm trying to achieve
x y y2
1 1 -0.7071
1 3 0.7071
2 4 0.7071
2 3 -0.7071
3 5 -0.2182
3 2 1.0910
3 3 -0.8728