keep() enables you to put in a vector of variable names which then are kept
inside the given data frame. All other variables are dropped.
dropp() enables you to put in a vector of variable names which then are dropped
from the given data frame. All other variables are kept.
Examples
# Example data frame
my_data <- dummy_data(1000)
# Call function
new_dt1 <- my_data |> keep(year, age, sex)
new_dt2 <- my_data |> keep(weight, income, education, sex, order_vars = TRUE)
new_dt3 <- my_data |> dropp(year, age, sex)
# Also works with characters
new_dt4 <- my_data |> keep("year", "age", "sex")
new_dt5 <- my_data |> dropp("year", "age", "sex")
# Or variable names stored as a character vector
var_names <- c("age", "sex", "income", "weight")
new_dt6 <- my_data |> keep(var_names)
new_dt7 <- my_data |> dropp(var_names)
