Assign Index_Class for based on user input fields. If use the same name of an existing field the information will be overwritten.

Multiple criteria are treated as "AND" so all must be met to be assigned to a particular Index_Class.

Internally uses `tidyr` and `dplyr`

If Index_Class is included in data then it is renamed Index_Class_Orig and returned in the output data frame.

assign_IndexClass(
  data,
  criteria,
  name_indexclass = "INDEX_CLASS",
  name_indexname = "INDEX_NAME",
  name_siteid = "SITEID",
  data_shape = "WIDE"
)

Arguments

data

Data frame (wide format) with metric values to be evaluated.

criteria

Data frame of metric thresholds to check.

name_indexclass

Name for new Index_Class column. Default = INDEX_CLASS

name_indexname

Name for Index Name column. Default = INDEX_NAME

name_siteid

Name for Site ID column. Default = SITEID

data_shape

Shape of data; wide or long. Default is 'wide'

Value

Returns a data frame with new column added.

Details

Requires use of reference file with criteria.

Examples

# Packages
library(readxl)

# EXAMPLE 1
# Create Example Data
df_data <- data.frame(SITEID = paste0("Site_", LETTERS[1:10])
                     , INDEX_NAME = "BCG_MariNW_Bugs500ct"
                     , GRADIENT = round(runif(10, 0.5, 1.5), 1)
                     , ELEVATION = round(runif(10, 700, 800), 1))

# Import Checks
df_criteria <- read_excel(system.file("extdata/IndexClass.xlsx"
                                          , package = "BioMonTools")
                          , sheet = "Index_Class")

# Run Function
df_results <- assign_IndexClass(df_data, df_criteria, "INDEX_CLASS")

# Results
df_results
#>    SITEID           INDEX_NAME GRADIENT ELEVATION   INDEX_CLASS
#> 1  Site_A BCG_MariNW_Bugs500ct      0.6     787.5 LoGrad-HiElev
#> 2  Site_B BCG_MariNW_Bugs500ct      1.3     717.5 HiGrad-LoElev
#> 3  Site_C BCG_MariNW_Bugs500ct      1.1     703.4 HiGrad-LoElev
#> 4  Site_D BCG_MariNW_Bugs500ct      0.7     732.0 LoGrad-LoElev
#> 5  Site_E BCG_MariNW_Bugs500ct      0.5     740.2 LoGrad-LoElev
#> 6  Site_F BCG_MariNW_Bugs500ct      1.0     719.6 HiGrad-LoElev
#> 7  Site_G BCG_MariNW_Bugs500ct      1.0     740.4 HiGrad-LoElev
#> 8  Site_H BCG_MariNW_Bugs500ct      0.8     706.4 LoGrad-LoElev
#> 9  Site_I BCG_MariNW_Bugs500ct      1.2     738.9 HiGrad-LoElev
#> 10 Site_J BCG_MariNW_Bugs500ct      1.3     797.6 HiGrad-HiElev