Error with percentile

Hello everybody,

I have data like that. I would like to calculate the breakpoints at 30% and 70% for variable "BTM" each year.
I tried this code but this code has an error. I would like to ask for help. Thank you in advance.

        yyyy = c(2000L,2000L,2001L,2001L,2001L,2001L,
         BTM = c(4.99137e+21,3.352767396e+21,
      ticker = as.factor(c("REE","SAM","BBC",
        code = as.factor(c("REE2000","SAM2000",

My code

percentile<- df%>% group_by(yyyy) %>% 
  quantile(BTM,probs = c(0.3, 0.7),na.rm=TRUE)

Best regards,

The quantile function will not be affected by the result of the group_by function and it also does not know that BTM is a column within df. You need to wrap quantile within summarize() to fix those two problems and then have quantile return one value at a time.

percentile<- df%>% group_by(yyyy) %>% 
  summarize(Q30 = quantile(BTM,probs = c(0.3),na.rm=TRUE),
         Q70 = quantile(BTM,probs = c(0.7),na.rm=TRUE))
1 Like

Thank you for for quick reply.

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