Tutorial by Examples

apply is used to evaluate a function (maybe an anonymous one) over the margins of an array or matrix. Let's use the iris dataset to illustrate this idea. The iris dataset has measurements of 150 flowers from 3 species. Let's see how this dataset is structured: > head(iris) Sepal.Length Sep...
for a large number of files which may need to be operated on in a similar process and with well structured file names. firstly a vector of the file names to be accessed must be created, there are multiple options for this: Creating the vector manually with paste0() files <- paste0("f...
In this exercise, we will generate four bootstrap linear regression models and combine the summaries of these models into a single data frame. library(broom) #* Create the bootstrap data sets BootData <- lapply(1:4, function(i) mtcars[sample(1:nrow(mtcars), ...
Built-in functionals: lapply(), sapply(), and mapply() R comes with built-in functionals, of which perhaps the most well-known are the apply family of functions. Here is a description of some of the most common apply functions: lapply() = takes a list as an argument and applies the specified ...
User-defined functionals Users can create their own functionals to varying degrees of complexity. The following examples are from Functionals by Hadley Wickham: randomise <- function(f) f(runif(1e3)) lapply2 <- function(x, f, ...) { out <- vector("list", length(x...

Page 1 of 1