From the course: R for Data Science: Analysis and Visualization
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Recoding variables - R Tutorial
From the course: R for Data Science: Analysis and Visualization
Recoding variables
- [Instructor] Sometimes your data is in great shape right as it comes to you, and sometimes it requires a little bit of work or, if you've worked in any real data projects, sometimes it needs a lot of work. But right now I want to show you how to do some very basic recoding of variables in R. It's a common task and it's going to make your life a little easier here. Let's start by loading our two packages and then bringing in our data set. And I'm going to switch so all of the character variables become factors in a single command here. All right. What we're going to do is we're going to create some new categories using recode. And here's how this works. First off, I'm going to use the command mutate. That is from the tidyverse and it tells it that I'm going to change a variable and I'm going to create a new variable called relaxed. And I'm going to do that by doing a recode on the variable psych region. And what…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.