#We will start by creating a character and numeric vector

xmas <- c("naughty","nice","nice","naughty","nice","naughty","nice","naughty")
kids_age <-c(2,6,7,10,3,4,5,9)

#We can get the max and min ages of kids with these two functions:

max(kids_age)
## [1] 10
min(kids_age)
## [1] 2
#We can also get the mean:
mean(kids_age)
## [1] 5.75
#We use function tapply() to get the mean age in each category: naughty vs. nice.

#Use ?tapply() to learn more about this function.

#tapply() sort of creates a table, that lets us look at values of one variable
#at different levels of another

#irst we specify our X values, then our factors, then the function we wish to apply.

tapply(kids_age, xmas, mean)
## naughty    nice 
## 6.25 5.25