Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Created December 17, 2015 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudhjayaraman/84ebedcc247aa1270798 to your computer and use it in GitHub Desktop.
Save anirudhjayaraman/84ebedcc247aa1270798 to your computer and use it in GitHub Desktop.
Adding multiple variables at once using mutate()
# 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