One of R`s cool features is functional programming. It makes development much easier and the code you write shorter and less prone to errors. There are few tool kits for functional programming in R (with famous
apply functions family among them). In this set of exercises, you will familiarize yourself with basic functions from the
purrr package, which has a great advantage of being consistent both internally and with the rest of the
Answers to the exercises are available here.
Please do all exercises using the
purrr package. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
purrr package. For each column in the
mtcars data set, calculate the mean. Results should be a list.
Do the same thing as above, but returning the named vector as a result.
Calculate the mean once again, but with max/min 10% values trimmed.
cyl into a list and calculate the number of rows for each element of the list.
For each element of lists from Exercise 4, calculate the mean of each column. Return results as a
data.frame with one record for each input element (3 rows in total).
For each element of the list from Exercise 4, fit a linear model between 1/4 mile time and gross horsepower.
For each model from the previous exercise, extract the co-efficient table.
Fit each of the models to all
For each model, plot separate histograms of the predicted value with the model indicated in the title.
For each car, calculate the average prediction of the models.
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below