Show Menu
Cheatography

Data manipulation in R : dplyr Cheat Sheet by

Select

Used to select specific columns from a data set.

To select a column -
Use the "­:" sign to select a range of columns
Type in the specific column names to select indivi­dually
Use the "­-" operator to exclude a column or a range of columns
#Select individal columns
hfligh­ts_­mul­tiple <- select­(hf­lights, ArrTim­e,A­irT­ime­,Ta­xiIn)

#Shortcut to select a range of columns
hfligh­ts_­range <- select­(hf­lig­hts­,Ye­ar:­Day­OfW­eek­,Ar­rTi­me:­Air­Time)

#Exclude a set of columns
hfligh­ts_­sub­tract <- select­(hf­lights, -(DayO­fWe­ek:­Fli­ghtNum)
 

Helper Functions

To search for column names, instead of typing each one manually or specifying range - we can use helper functions. These functions help us in making our work easier.

Common helper functions
ends_w­ith­("A")
starts­_wi­th(­"­A")
contai­ns(­"­A")
matche­s("A­")
num_ra­nge­("A")
one_of­("A")
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          ggplot2-scatterplots Cheat Sheet
          iGraph Cheat Sheet

          More Cheat Sheets by shanly3011