The data manipulations provided by dplyr are some of the core and most useful functions in the Tidyverse package set. The best documentation is provided by the developers and there is an excellent cheatsheet available (see Dat Transformation Cheat Sheet). This page is used to record common processes that may or may not be clearly covered in the cheatsheets.

The following examples will work if you have dplyr available.

# Recommended, this loads all the related packages

# Alternate, this loads just dplyr

# Because some statements exist in multiple packages you can use them in two ways

Select/Extract/Remove Specific Columns from a tibble

# The select() statement allows you to manipulate columns in a tibble
# The operators can either select or drop columns, if you want to drop a columns add the "-" in front of the operator.

# Extract column example
select(starts_with('TNF'))   # any column name that starts with 'TNF'

# Drop column example, adding "-" tells select to drop the column as opposed to the default extraction
select(-starts_with('TNF'))   # any column name that starts with 'TNF'

# Operators that can be used
select(starts_with('TNF'))   # any column name that starts with 'TNF'
select(ends_with('RAS'))     # any column name that ends with 'RAS'
select(contains('RAS'))      # any column name that contains 'RAS'
select(num_range(HRAS:NRAS)) # the range of columns from 'HRAS' to 'NRAS'
select(matches('^f.+R$'))    # any column name matching the regex pattern
select(everything())         # often used get rest of table after extraction of specific columns
select(last_col())           # selects the last column of the matrix
select(one_of())             # selects columns from a list