Data Rank Question with Time series

I want to ask a rank question.
suppose i have a data.frame just like following

df <-   tibble(year = rep(c(1990,1991,1992),3),
         num = c(1,2,3,2,2,3,4,1,2))

i want to get the rank with following

x <- 
  tibble(year = rep(c(1990,1991,1992),3),
         num = c(1,2,3,2,2,3,4,1,2),
         rank_1 = c(3,2,1,2,2,1,1,3,2))

that is say, the more lagre the num, the more little the rank_1. and when num is equal, we would choose the max rank

and may be use

group_slice
rank
purrr::map 

can solve that question . but i have no idea how to use them .

There should be some kind of key to identify each time series.

df <-   tibble(year = rep(c(1990,1991,1992),3),
               num = c(1,2,3,2,2,3,4,1,2),
               key = c("A", "A", "A", "B", "B", "B", "C", "C", "C"))

You can group by the key and then do the ranking. Try dense_rank() from the dplyr package.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.