Home > Mobile >  10th Percentile of a Time Column
10th Percentile of a Time Column

Time:11-26

I have a time column of the class "Period" [hms package]; how do I find the quantile of that column? I have tried converting to seconds and pulling out that 10th percentile value then trying to filter out the name of the individual of interest by doing df[df$time == 10thPerc, ] to no avail. I am wondering if there is something easier I can do to get that value because I need to compare it to another individual's time. The question is: How far is John from the top 10 percentile? I have John's time, but cannot use difftime to find the difference. I get an error about the "origin must be supplied.

My time column is in period class format so it looks like this:

Time
"34M 09S"
"1H 44M 35S"

I just want to compare two of these values.

CodePudding user response:

See this other question: Quantile Function for a Vector of Dates

Looks like you can use the quantile() function and add a type=1 argument

dates <- as.Date("01/01/1900", "%d/%m/%Y")   floor( 36500 * runif(100000) )

quantile(dates, probs = c(0.001, 0.025, 0.975, 0.999), type = 1)

        0.1%         2.5%        97.5%        99.9% 
"1900-02-04" "1902-06-23" "1997-06-10" "1999-10-30" 
  •  Tags:  
  • r
  • Related