R/nwos_estimates_add_minority.R

Defines functions add_minority

Documented in add_minority

#' Add MINORITY Variable to an NWOS Data Set
#'
#' Add variables to an NWOS data frame
#' @usage nwos_estimates_add_minority(x = NA, data = QUEST)
#' @param x list number. Only applicable if is data is a list of data frames, instead of a single data frame. This used mainly for apply functions.
#' @param data data frame or list of data frames
#' @keywords nwos
#' @details
#' The default values create the variables used in the NWOS tables.
#' @export
#' @examples
#' nwos_estimates_add_minority()

add_minority <- function(x = NA, data = QUEST) {
  require(tidyverse)
  if(!is.data.frame(data)) data <- data[[x]]
  data %>%
    mutate(OWN1_MINORITY = factor(case_when(OWN1_ETH == 1 | OWN1_RACE_ASIAN == 1 | OWN1_RACE_BLACK == 1 |
                                             OWN1_RACE_HAWAIIAN == 1 | OWN1_RACE_INDIAN == 1 ~ 1,
                                          OWN1_ETH == -1 | OWN1_RACE_ASIAN == -1 ~ -1,
                                          OWN1_ETH == -2 | OWN1_RACE_ASIAN == -2 ~ -2, 
                                          TRUE ~ 0)))
}
familyforestresearchcenter/nwos documentation built on April 12, 2025, 11:54 a.m.