How do you calculate Spearman correlation by group in R. I found the following link talking about Pearson correlation by group. But when I tried to replace the type with spearman, it does not work.
https://stats.stackexchange.com/questions/4040/r-compute-correlation-by-group
How about this for a base R solution:
And then, if you want the results in the form of a data.frame:
EDIT: If you prefer a
plyr-based solution, here is one: