From the course: Learning the R Tidyverse

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Column-wise groups: Using the .by argument instead of group_by()

Column-wise groups: Using the .by argument instead of group_by() - R Tutorial

From the course: Learning the R Tidyverse

Column-wise groups: Using the .by argument instead of group_by()

- [Instructor] I need to tell you about the .by argument and how you could use that instead of group_by if you wanted to. Let's understand how this argument works by going to the project 04_06b and we'll open the by-argument.R script. Let's load the tidyverse on line one. In lines four through seven, we're making use of group_by and summarise to find the mean height of each combination of species and homeworld. This is the traditional way to work with groups. But recently the summarise, mutate, and the new reframe function got a .by argument. Let's see that in action. Let's copy this code, let's paste it, and let's add the argument .by. And we need to give it a vector of the columns to group by, so we're going to group by species and homeworld. Then, we can get rid of our group_by function core. And now when we run this code, we're going to get the same output as before in terms of we will have the mean height per combinations of species and homeworld. But by using the .by argument…

Contents