dplyr verbs logo dplyr verbs: select

1 2 3 4 5 6 7
Notes

Once again we assume that you've got the dataframe set up appropriately.

library(tidyverse)

# This command makes sure that the chickweight dataframe is clean.
df <- ChickWeight %>% ungroup() %>% as.data.frame()

You can select columns but you can also deselect them.

# Select the columns to keep.
df %>%
  filter(Diet == 3) %>%
  mutate(growth = weight/(Time + 1)) %>%
  select(weight, Time, Chick, growth)

# Select the columns to remove.
df %>%
  filter(Diet == 3) %>%
  mutate(growth = weight/(Time + 1)) %>%
  select(-Diet, -weight)