Writing Functions in R

Examples

Using the athlete_events.csv file, use the teenagecount function to display the number of teenagers in the Olympics Athlete Events data.

teenagecount <- function(x) {length(x[(x >= 13) & (x <= 19) & (!is.na(x))])}
Click to see solution
olympicDF <- read.csv("/anvil/projects/tdm/data/olympics/athlete_events.csv")

teenagecount <- function(x) {length(x[(x >= 13) & (x <= 19) & (!is.na(x))])}

teenagecount(olympicDF$Age)
32250