Statistical Summaries
Quantiles
Cut Points in a Vector
quantile reports values at requested probabilities, such as the middle or quartile cut points.
Program
Play the script to choose a probability and read the matching score cut point.
quantiles.R
Replay: real traced execution (multi-file project)
scores <- c(4, 7, 9, 10, 12)
percent <- 0.50
cutoff <- as.numeric(quantile(scores, percent))
cat(cutoff, "\n", sep = "")
scores <- c(4, 7, 9, 10, 12)
percent <- 0.25
cutoff <- as.numeric(quantile(scores, percent))
cat(cutoff, "\n", sep = "")
scores <- c(4, 7, 9, 10, 12)
percent <- 0.75
cutoff <- as.numeric(quantile(scores, percent))
cat(cutoff, "\n", sep = "")
scores ← 4, 7, 9, 10, 12
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.50values this step4, 7, 9, 10, 12scorespercent ← 0.50
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.503cutoff <- as.numeric(quantile(scores, percent))values this step0.50percentcutoff ← 9
2percent <- 0.503cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")values this step9cutoff4, 7, 9, 10, 12scores0.50percentcat(cutoff, " ", sep = "")
3cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")output9values this step9cutoff
scores ← 4, 7, 9, 10, 12
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.25values this step4, 7, 9, 10, 12scorespercent ← 0.25
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.253cutoff <- as.numeric(quantile(scores, percent))values this step0.25percentcutoff ← 7
2percent <- 0.253cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")values this step7cutoff4, 7, 9, 10, 12scores0.25percentcat(cutoff, " ", sep = "")
3cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")output7values this step7cutoff
scores ← 4, 7, 9, 10, 12
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.75values this step4, 7, 9, 10, 12scorespercent ← 0.75
1scores <- c(4, 7, 9, 10, 12)2percent <- 0.753cutoff <- as.numeric(quantile(scores, percent))values this step0.75percentcutoff ← 10
2percent <- 0.753cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")values this step10cutoff4, 7, 9, 10, 12scores0.75percentcat(cutoff, " ", sep = "")
3cutoff <- as.numeric(quantile(scores, percent))4cat(cutoff, "\n", sep = "")output10values this step10cutoff
quantile
`quantile(scores, percent)` returns the cut point for a probability.
as.numeric
`as.numeric` strips names from the quantile result for simple output.
probability
`0.50` asks for the median; `0.25` and `0.75` ask for quartiles.