

But if you'd like to learn more, head to the purrr website and/or Jenny Bryan's purrr tutorial site. Purrr is a bit beyond the scope of a basic beginner's guide.

Saunders has a nice brief introduction to apply in R in a blog post if you'd like to find out more and see some examples. Australian statistical bioinformatician Neal F.W. Other functions in the apply() family such as lapply() or tapply() deal with different input/output data types.

Returns the median of every row in my_matrix and You specify whether you're applying by rows or by columns by adding the argument 1 to apply by row or 2 to apply by column. Plain old apply() runs a function on every row or every column of a 2-dimensional matrix or data frame where all columns are the same data type. "These functions can sometimes be frustratingly difficult to get working exactly as you intended, especially for newcomers to R," says an blog post at Revolution Analytics, which focuses on enterprise-class R, in touting plyr over base R. There are more than half a dozen functions in the apply family, depending on what type of data object is being acted upon and what sort of data object is returned. I learned R using the older plyr package for this - and while I like that package a lot, it's essentially been retired. The apply() function group and in base R and functions in the tidyverse purrr package are designed for this. Typically in data analysis, though, you want to apply functions to more than one item in your data: finding the mean salary by job title, for example, or the standard deviation of property values by community. But in R, the primary assignment operator is 1 and only the first element will be used
