Calculating the percentage of days when the temperature is above the 95th quantile for multiple collumns

I have an xts file with 6000 collumns and 2000 rows, containing daily max temperatures for 6000 different places and I try to calculate the percentage of days on each one when the temperature is above the 95th percentile.
My initial thought was to calculate the 95th quantile for each one of them however when I use the quantile function, it doesnt work for each collumn seperately. Moreover unfortunetely it doesnt provide me the percentage of days, only the numeric value


I'm really stuck at this point so any help or suggestion is higly appreciated

Hi @Thanos64,

This is definitely do-able. Are you able to create a reproducible example (called reprex)? This would include a snippet of data that can be copy-and-pasted so users may provide working solutions.

I found a solution so I'll post it in case anyone needs some help in the future.

First I found the mean q95 for that period using the colquantile funtion

xx79<-matrix(as.numeric(max79_84),ncol = 5785,nrow=2192)

Then I made a variable that will count the number of times that I have days above that temperature

for (i in 1:6000) {


After that I made a loop to check the temperatures in every case, count the variables

for (j in 1:6000) {
for(i in 1:2000){
for (i in 1:6000) {

Hi. I am curious why you want to achieve these calculatons. By definition, the percentage of days above the 95th quantile is 5%...

Any way, a much simpler and faster way could be the following

Data <- data.frame(a = runif(100), b = rnorm(100), c = rexp(100))

qproc <- function(Data){
    return(mean(Data > quantile(Data, .95)))

sapply(Data, qproc)
   a    b    c 
0.05 0.05 0.05

Probably I wasnt very specific on the title, I try to create a map showing the magnitude of certain extreme climate indices throughout the country, in that case the tx95 one. Because of the nature of those indices, the percentage above the 95th quantile isnt equal to 5%.
Eventually the resulting maps eventually look like this one

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