I want to standardize the monthly signal in the range of [-1,1] by yyyymm.
I just know the code like below, but it did the standardize in the whole column. What I need is to standardize the signal month by monty.
df$x<- scale(df$signal, center = 0, scale = max(abs(df$signal)))
Thank you very much!
permno yyyymm signal
10001 201705 1.47
10026 201705 0.32
10028 201705 -0.36
10001 201706 1.45
10026 201706 0.31
10028 201706 0.22
10001 201707 -1.41
10026 201707 0.32
10028 201707 -0.28