Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Created December 17, 2015 12:37
Show Gist options
  • Save anirudhjayaraman/9952687b1e0fce262a22 to your computer and use it in GitHub Desktop.
Save anirudhjayaraman/9952687b1e0fce262a22 to your computer and use it in GitHub Desktop.
Select and Mutate
hflights[c('ActualElapsedTime','ArrDelay','DepDelay')]
# Equivalently, using dplyr:
select(hflights, ActualElapsedTime, ArrDelay, DepDelay)
# Print out a tbl with the four columns of hflights related to delay
select(hflights, ActualElapsedTime, AirTime, ArrDelay, DepDelay)
# Print out hflights, nothing has changed!
hflights
# Print out the columns Origin up to Cancelled of hflights
select(hflights, Origin:Cancelled)
# Find the most concise way to select: columns Year up to and
# including DayOfWeek, columns ArrDelay up to and including Diverted
# Answer to last question: be concise!
# You may want to examine the order of hflight's column names before you
# begin with names()
names(hflights)
select(hflights, -(DepTime:AirTime))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment