# Example data frame
my_data <- dummy_data(1000)
# Get row numbers
my_data <- my_data |> running_number()
my_data <- my_data |> running_number("row_number")
# Running number per variable expression
my_data <- my_data |> running_number(by = year)
# Mark first and last cases
my_data <- my_data |>
mark_case(by = household_id) |>
mark_case(var_name = "last", by = household_id, first = FALSE)
# Retain first value inside a group
my_data <- my_data |>
retain_value(var_name = c("household_weight", "household_icome"),
value = c(weight, income),
by = c(state, household_id))
# Retain sum inside a group
my_data <- my_data |>
retain_sum(var_name = c("weight_hh_sum", "icome_hh_sum"),
values = c(weight, income),
by = c(state, household_id))
# Retain columns inside data frame, which orders them to the front
my_data <- my_data |> retain_variables(age, sex, income)
# Retain columns inside data frame, but order them to the end.
# Variable ranges can also be used.
my_data <- my_data |> retain_variables(age:income, order_last = TRUE)
# Retain columns inside data frame and add new variables with all NA values
my_data <- my_data |> retain_variables(age, sex, income, status1:status5)
Run the code above in your browser using DataLab