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 a 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.
Calculate the factorial for numbers from 1 to 10.
data.frame with cross products of letters from a to z (first column) and numbers from 1 to 10 (second column).
list1 = list('a', data.frame(1:10), TRUE, 1, letters, 153) find the position of the first element of the list that is numeric.
list1, check if every element is of an atomic type.
Select only atomic elements of
Check if the letter ‘b’ is an element of
log for each element of
list1 and handle errors.
Run each function from the list
list2 = list(rnorm, runif, rcauchy) to generate 10 samples.
Generate 5 series of 10 samples each from uniform distribution
Combine the list of series from exercise 9 into a single vector.
- 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