Hello guys.
I am a bit lost here and cannot find the solution.
Please see the code below.
I have a data frame and I want to select specific columns.
Naturally this is dummy code, but in my actual problem, I get the variables from an operation, and they get stored in a variable.
How do I make the data frame, "fastDummies_example", return only the columns found in the variable "variables_I_want"
fastDummies_example<- data.frame(numbers = 1:3,
gender = c("male", "male", "female"),
animals = c("dog", "dog", "cat"),
owner = c("Fernandes", "Eric", "Ivanov"),
dates = as.Date(c("2012-01-01", "2011-12-31",
"2012-01-01")),
stringsAsFactors = FALSE)
fastDummies_example
variables_I_want <- c("animals", "owner")
fastDummies_example %>% select(colnames() %in% variables_I_want)