Friday, April 1, 2016

dplyr's select Function

# A data frame businesshours is pre-loaded in the workspace.

# Load the `dplyr` package into the memory.
library("dplyr")

# Use the `select()` function to select all variables starting with the variable "period" until "QR3" and all the variables in between them.
select(businesshours, period:QR3)

# Use the `select()` function to select all variables that contain "o".
select(businesshours, contains("o"))

# Use the `select()` function to select all variables that starts_with "Q".
select(businesshours, starts_with("Q"))

# Use the `select()` function to select all variables with a numeric range from 2 to 4 and starting with "QR".
select(businesshours, num_range("QR", 2:4))

# Use the `select()` function to select all variables that DO NOT have a numeric range from 2 to 4 and starts with "QR".
select(businesshours, -num_range("QR", 2:4))

No comments:

Post a Comment