I am trying to get values of ranked variables in R. I am calculating annualized standard deviations for a number of commodities. I then rank the standard deviations across years for each commodity. Although I understand the output, I am looking for a better way to associate the year values to the ranked output. My code is below:
annualizedSD <- function(x)
{
annSD = sd(x) * sqrt(length(x))
}
sdByContractByYear <- summaryBy(Settle~contract+yr,data=commodityData, FUN=annualizedSD)
rankSDByContractByYear <- summaryBy(-Settle.annualizedSD~contract, data=sdByContractByYear, FUN=rank)
The output rankings for each year are labeled "Settle.annualizedSD.FUN1, ...FUN2, ... FUN3, ... etc." What I am looking for is the 'yr' or year value, e.g. 1995, 1996, 1997, etc, instead of FUN1, FUN2, etc...
How do I get R's 'rank' function to provide the label of the ranks by year?