The tidyverse collection of packages is a suite of packages that simplifies a huge number of the commonest tasks I do in R. It’s become indispensable for me, and I’ll make heavy use of it.
I draw your attention to dplyr, one of the tidyverse packages. It provides a set of functions that makes manipulating data frames a lot neater. You can filter, select, sort, and create new columns in a much neater way than using R’s… esoteric… native syntax.
I strongly recommend visiting — and bookmarking — their website.
Here’s one example of how the clarity of a piece of code can improve. Suppose you want to subset the (inbuilt)
iris data frame according to the width of the sepals and the length of the petals. In the traditional R way, you might write
iris[iris$Sepal.Width < 3.25 & iris$Petal.Length < 5, ]
But using dplyr, it’s
filter(Sepal.Width < 3.25) %>%
filter(Petal.Length < 5)
I will use
mutate from the dplyr package,
crossing from the tidyr package, and many functions from the stringr package frequently.