New Book: A Short Introduction to Applied Statistical Programming in R

I have a new book in progress called A Short Introduction to Applied Statistical Programming in R, which can be viewed online as a Gitbook or as a PDF. [EDIT 2020-04-01: I will primarily focus on the Gitbook version, as I am running into some typesetting issues with the PDF at the moment.]

[EDIT 2020-04-02: The Gitbook version is fairly complete and I do not foresee many major updates to it unless they are requested or if I think of anything else significant to add. The PDF version is still in progress due to the aforementioned typesetting issues I am encountering.]

It is essentially a textbook targeted toward social science students that teaches them the basics of R, primarily focusing on Base R rather than making use of external libraries (although, some are mentioned and demonstrated such as ggplot2).

One advantage of this textbook over others is the extensive use of summary tables at the end of each chapter: below is an example from the Functionals chapter.

[EDIT 2020-04-01: Previously, the summary of string functions were displayed. I’ve chosen to use the Functionals summary now that I’ve finished writing its descriptions.]

[EDIT 2020-05-12: tapply() has now been added. I initially excluded it, as I thought that students may find aggregate()’s data frame output to be more useful. However, there were times when I needed a vector output from a group-wise computation; thus, requiring tapply() for such an operation (or at least simplified it). In turn, I added the function to the book, as students may come across similar situations themselves.]

Summary of Functionals

Function

Description

Example

lapply(X, FUN)

Compute a function over data and output a list.

lapply(mtcars, mean)

sapply(X, FUN)

Compute a function over data and output a matrix (sometimes a list, depending on the function being passed).

sapply(mtcars, mean)

apply(X, MARGIN, FUN)

Compute a function row-wise or column-wise.

apply(mtcars, 1, mean); apply(mtcars, 2, mean)

vapply(X, FUN, FUN.VALUE)

Compute a function over data and check if the output matches a pre-specified type.

vapply(mtcars, mean, numeric(1))

mapply(FUN, ...)

Compute a function over one or more data inputs and output an array (vector or matrix).

mapply(rbind, mtcars\$mpg, mtcars\$wt)

Map(f, ...)

Compute a function over one or more data inputs and output a list.

Map(rbind, mtcars\$mpg, mtcars\$wt)

rapply(object, f, classes)

Recursively compute a function over data and output a vector or list.

rapply(iris, mean, classes = "numeric")

tapply(X, INDEX, FUN)

Generate grouped computations and output a vector.

with(iris, tapply(Sepal.Length, Species, mean))

aggregate(formula, data, FUN)

Generate grouped computations and output a data frame.

aggregate(mpg ~ gear, mtcars, mean)

This book is the first time I am writing a textbook: most of my writings in the past have been academic papers, documentation for my packages1, and blog posts (of course, as you are reading this!), so I hope that you and others learn a lot from this book!