Selecting variables

PHOTO EMBED

Wed Aug 11 2021 06:02:32 GMT+0000 (Coordinated Universal Time)

Saved by @ahwazakhtar

drop.cols <- c('Sepal.Length', 'Sepal.Width')
starwars %>% 
  select(-(name:mass)) %>%        # the range of columns from 'name' to 'mass'
  select(-contains('color')) %>%  # any column name that contains 'color'
  select(-starts_with('bi')) %>%  # any column name that starts with 'bi'
  select(-ends_with('er')) %>%    # any column name that ends with 'er'
  select(-matches('^f.+s$')) %>%  # any column name matching the regex pattern
  select_if(~!is.list(.)) %>%     # not by column name but by data type
  select(-one_of(drop.cols))	  # not one of the drop columns
  head(2)
content_copyCOPY

https://stackoverflow.com/questions/35839408/r-dplyr-drop-multiple-columns