Below are the solutions to these exercises on Optimize Data Exploration With Sapply().

#################### # # # Exercise 1 # # # #################### dataset1 <- data.frame(observationA = 16:8, observationB = c(20:19, 6:12)) sapply(dataset1, length)

## observationA observationB ## 9 9

#################### # # # Exercise 2 # # # #################### sapply(dataset1, sum)

## observationA observationB ## 108 102

#################### # # # Exercise 3 # # # #################### sapply(dataset1, quantile)

## observationA observationB ## 0% 8 6 ## 25% 10 8 ## 50% 12 10 ## 75% 14 12 ## 100% 16 20

#################### # # # Exercise 4 # # # #################### sapply(dataset1, class)

## observationA observationB ## "integer" "integer"

#################### # # # Exercise 5 # # # #################### DerivativeFunction <- function(x) { log10(x) + 1 } sapply(dataset1, DerivativeFunction)

## observationA observationB ## [1,] 2.204120 2.301030 ## [2,] 2.176091 2.278754 ## [3,] 2.146128 1.778151 ## [4,] 2.113943 1.845098 ## [5,] 2.079181 1.903090 ## [6,] 2.041393 1.954243 ## [7,] 2.000000 2.000000 ## [8,] 1.954243 2.041393 ## [9,] 1.903090 2.079181

#################### # # # Exercise 6 # # # #################### sapply(dataset1, function(x) log10(x) + 1)

#################### # # # Exercise 7 # # # #################### sapply(dataset1, range)

## observationA observationB ## [1,] 8 6 ## [2,] 16 20

#################### # # # Exercise 8 # # # #################### sapply(dataset1, print)

## [1] 16 15 14 13 12 11 10 9 8 ## [1] 20 19 6 7 8 9 10 11 12

## observationA observationB ## [1,] 16 20 ## [2,] 15 19 ## [3,] 14 6 ## [4,] 13 7 ## [5,] 12 8 ## [6,] 11 9 ## [7,] 10 10 ## [8,] 9 11 ## [9,] 8 12

#################### # # # Exercise 9 # # # #################### sapply(dataset1, mean)

## observationA observationB ## 12.00000 11.33333

#################### # # # Exercise 10 # # # #################### sapply(dataset1, is.numeric)

## observationA observationB ## TRUE TRUE

Koleen Paunon says

This is really great! Thanks