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:

## Leave a Reply