Skip to content

Instantly share code, notes, and snippets.

@rudeboybert
Last active November 28, 2016 17:40
Show Gist options
  • Save rudeboybert/e34adae51cc7085efb8b6b7f81d509b1 to your computer and use it in GitHub Desktop.
Save rudeboybert/e34adae51cc7085efb8b6b7f81d509b1 to your computer and use it in GitHub Desktop.
Mean age of 3 randomly chosen 116 students
library(lubridate)
library(dplyr)
library(mosaic)
set.seed(41)
students <- c(
"Annie", "Caroline", "David", "Ian", "Jack", "Jared", "Joccelyn", "Joe",
"Julia", "Luisangel", "Madeline", "Rebecca", "Samuel", "Sarah", "Sierra",
"Sophia", "Stefan", "Steven", "Theodore", "Tina", "Wengel", "William", "Zach"
)
# Compute the sample mean age once
resample(students, size=3, replace=FALSE)
birthdays <- c("2000-01-01", "2000-01-01", "2000-01-01")
ages <- interval(ymd(birthdays), ymd("2016-11-28")) / dyears(1)
mean(ages)
# Do it again...
# Do it once more...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment