Skip to contents

This function subsets a dataframe so it keeps only one chosen response variable plus all other columns that are not in the set of response variables.

Usage

select_one_response(gbm_data, chosen_response, response_vars, reorder = TRUE)

Arguments

gbm_data

data.frame. The full dataset containing responses and predictors.

chosen_response

character. The name of the response variable you want to keep.

response_vars

character vector. A list of all possible response variables.

reorder

logical. If TRUE, the chosen response column is moved to the front of the new data frame. Defaults to TRUE.

Value

A data frame that includes only the chosen response column (plus all columns that were not in response_vars).

Examples

if (FALSE) { # \dontrun{
# Suppose 'response_vars' contains c("sonchus_arvensis", "cirsium_arvense", ...)
# and 'gbm_data' is your data frame with those columns plus predictors.

# Keep only "cirsium_arvense" as the response:
new_data <- select_one_response(
    gbm_data        = gbm_data,
    chosen_response = "cirsium_arvense",
    response_vars   = response_vars,
    reorder         = TRUE
)

# Check the first few columns:
head(new_data)
} # }