# Optimize Data Exploration With Sapply() – Exercises

October 14, 2016
By

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The `apply()` functions in R are a utilization of the Split-Apply-Combine strategy for Data Analysis, and are a faster alternative to writing loops.

The `sapply()` function applies a function to individual values of a dataframe, and simplifies the output.

Structure of the `sapply()` function: `sapply(data, function, ...)`

The dataframe used for these exercises:
`dataset1 <- data.frame(observationA = 16:8, observationB = c(20:19, 6:12))`

Answers to the exercises are available here.

Exercise 1

Using `sapply()`, find the length of `dataset1`‘s observations:

Exercise 2

Using `sapply()`, find the sums of `dataset1`‘s observations:

Exercise 3

Use `sapply()` to find the quantiles of `dataset1`‘s columns:

Exercise 4

Find the classes of `dataset1`‘s columns:

Exercise 5

Required function:
`DerivativeFunction <- function(x) { log10(x) + 1 }`

Apply the “`DerivativeFunction`” to `dataset1`, with simplified output:

Exercise 6

Script the “`DerivativeFunction`” within `sapply()`. The data is `dataset1`:

Exercise 7

Find the range of `dataset1`:

Exercise 8

Print `dataset1` with the `sapply()` function:

Exercise 9

Find the `mean` of `dataset1`‘s observations:

Exercise 10

Use `sapply()` to inspect `dataset1` for `numeric` values:

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.