| keep_dropp | R Documentation |
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.
keep(data_frame, ..., order_vars = FALSE)
dropp(data_frame, ...)
data_frame |
A data frame which should be reduced to (keep) or by (drop) the specified variables. |
... |
The variable names to keep/drop. |
order_vars |
keep: At the end variables are ordered as specified in the command. |
Returns a reduced data table.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.