5.0 / 5
We will cover the following tasks in 32 minutes:
In this lesson I’m going to introduce you to the dataset and a few of the topics we will be covering. While I’m doing that I’ll show you how to use the Rhyme Interface (in case you don’t know already) and give you a short bio. Remember that learning R is easy but does take some practice. The good thing, however, is that it isn’t like learning classical piano.
The verb Mutate is one of the more powerful verbs in the dplyr suite. The verb can create new variables while preserving the old ones. And here’s a cliff hanger. You can pass homemade functions (user defined functions) through the Mutate function. Why would you do this? To save yourself time in creating a for loop. But first things first. Come in and get a refresher.
In this chapter we’re going to create a few new variables in our data. This manipulation will allow us to easily spot which animals sleep the least. This is a common manipulation when looking at data for the first time. Come in and I’ll show you how this is done.
Mutating Rows as opposed to Columns
What? You can manipulate data rowise? Yep. In this lesson I will show you how. I will also share an inspiring story about the day that you take the training wheels off of R and make it your goto for data analytics.
Mutate with an If Else Statement
There are multiple ways to do the same thing in R. But. You should always be on the lookout for the most elegant way of doing something. In this example I’m going to show you how to do an If Else statement within a mutate function. While it’s pretty easy to do the same thing Base R way but it’s more efficient and elegant to do it the way I’ll show you. And it’s consistent with the rest of the code. Let’s get after it.
When scraping data you will quickly learn that the data often needs to be cleaned. For example spaces need to be removed, certain character, and maybe you need to change some characters to upper or lower (or any combination of things). Using the Mutate All function you can do this in a singular step - instead of creating complicated for loops or functions. If you haven’t taken my data harvesting course on web scraping this will be a handy function for some of those problems. Let’s just go over this now.
You’ve done well. At this point you can do basic functions along with some more complicated ones. I recommend you practice for a couple weeks every day and then put the R training wheels in the garage and go for a cruise. Thank you for your time. I’ll see you in the next course.
About the Host (Chris Shockley)
I am an R enthusiast, hiker, and amateur astronomer. My favorite hike is located in Mt. Rainier National Park, my favorite Deep Sky Object is Alberio, and my favorite R package is dplyr (since I use it everyday). I have a dog named Coog (Lllasa Apso)., I work as a Data Analyst/Financial Analyst for a Metals Co. located in Seattle, WA. I have been in my current position for 5 years. I work in SQL, R, R Shiny, QGIS. Because I have traveled the roads you are on I believe I will be an asset and will add value to your programming repertoire. We will walk through multiple examples and get to know each other through the process. Don't take my word for it though. Come on in and take a Project or two. Regards, Chris Shockley