Skip to content

Instantly share code, notes, and snippets.

@anaerobeth
Created August 12, 2015 14:47
Show Gist options
  • Save anaerobeth/705f85672c2658e3c377 to your computer and use it in GitHub Desktop.
Save anaerobeth/705f85672c2658e3c377 to your computer and use it in GitHub Desktop.
calculate quantiles in R
# launch R console from Mac Spotlight
# navigate to file directory
setwd("/Users/Tenorio/Desktop")
# load the file 'times.txt' in table format
counts <- read.table('times.txt')
# check if the file is read properly
# V1 is the default column name if no column title is specified
# head() will show the first 6 values imported
head(counts)
# calculate the default quantile values:
# 0% 25% 50% 75% 100%
quantile(counts$V1)
# calculate custom quantile values:
# 25% 50% 95%
quantile(counts$V1, c(.25, .5, .95))
# calculate custom quantile values to visualize outliers or extreme values
# p is the list of all values to check
p <- c(0.1, 0.2, 0.4, 0.6, 0.8, 1, 2, 4, 6, 8, 10, 20, 30, 40, 50, 60, 70, 80, 90, 92, 94, 96, 98, 99, 99.2, 99.4, 99.6, 99.8, 99.9, 100)
q5 <- quantile(counts$V1, probs = p/100)
# create the graph
plot(p,q5)
# to save quartz plot to pdf file: File > Save > Dialog...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment