From the course: Learning the R Tidyverse
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Using the mutate() function to modify and add columns - R Tutorial
From the course: Learning the R Tidyverse
Using the mutate() function to modify and add columns
- [Instructor] mutate() is your friend when it comes to wrangling data sets with a tidyverse and is from the dplyr package. mutate() allows us to modify existing columns or to create new columns in data.frame and tibble. Let's take a look at how to use the function in the 01_10b project. At the top of the script, we're loading the tidyverse as always, and then on lines 11 and 12, I've got an advanced option that I'll get to after the basics of using mutate(). So, we're going to be looking at the msleep dataset. Let's print that to the console and make the console a little bit bigger, and we can see that we've got many columns about sleep. What we don't have at the moment is we don't have a non-REM sleep column. So we have sleep_total, we have sleep_rem, but we don't have a non-REM sleep. So, let's create that new column with mutate(). We'll pipe our dataset and sleep into the mutate() function and we're going to create a new column, sleep_non_rem, and we'll calculate sleep_total. You…
Contents
-
-
-
What is the tidyverse?2m 22s
-
Installing, loading, and working with the tidyverse packages5m 1s
-
(Locked)
Introducing data.frame and tibbles8m 34s
-
What are %>% and |> for in the tidyverse3m 46s
-
(Locked)
Using the %>% pipe in your code5m
-
(Locked)
Using the |> pipe in your code6m 18s
-
(Locked)
Datasets built into the tidyverse packages3m 15s
-
(Locked)
Using the select() function to obtain columns from data4m 23s
-
(Locked)
Using the filter() function to filter data by conditions6m 10s
-
(Locked)
Using the mutate() function to modify and add columns4m
-
(Locked)
Challenge: Rewrite this code to use the pipe of your choice2m 38s
-
(Locked)
Solution: Rewrite this code to use the pipe of your choice3m 19s
-
-
-
-
-
-
-