Purpose
Can I select columns using dplyr
conditional that the column name is in an external vector. I have found some posts that explain how to subset the data frame using a vector of name, but I could not find one when some of the names in the vector do not exist in the data frame.
Example dataset
library(tidyverse)
library(tibble)
library(data.table)
col_names <- c('a', 'b', 'e')
rename <- dplyr::rename
select <- dplyr::select
set.seed(10002)
a <- sample(1:20, 1000, replace=T)
set.seed(10003)
b <- sample(letters, 1000, replace=T)
set.seed(10004)
c <- sample(letters, 1000, replace=T)
data <-
data.frame(a, b, c)
# I would like to choose a, b that are in col_names vector.