Created
December 17, 2015 16:07
-
-
Save anirudhjayaraman/84ebedcc247aa1270798 to your computer and use it in GitHub Desktop.
Adding multiple variables at once using mutate()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a second variable loss_percent to the dataset: m1 | |
m1 <- mutate(hflights, loss = ArrDelay - DepDelay, loss_percent = ((ArrDelay - DepDelay)/DepDelay)*100) | |
# mutate() allows you to use a new variable while creating a next variable in the same call | |
# Copy and adapt the previous command to reduce redendancy: m2 | |
m2 <- mutate(hflights, loss = ArrDelay - DepDelay, loss_percent = (loss/DepDelay) * 100 ) | |
# Add the three variables as described in the third instruction: m3 | |
m3 <- mutate(hflights, TotalTaxi = TaxiIn + TaxiOut, ActualGroundTime = ActualElapsedTime - AirTime, Diff = TotalTaxi - ActualGroundTime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment