The output of metric.values() is saved to Excel with different groups of metrics on different worksheets.
metvalgrpxl(
fun.DF.MetVal,
fun.DF.xlMetNames = NULL,
fun.Community,
fun.MetVal.Col2Keep = c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS"),
fun.xlGrpCol = "Sort_Group",
file.out = NULL
)
Data frame of metric values.
Data frame of metric names and groups. Default (NULL) will use the verion of MetricNames.xlsx that is in the BioMonTools package.
Community name of calculated metric values (bugs, fish, or algae)
Column names in metric values to keep. Default = c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS")
Column name from Excel metric names to use for Groupings. Default = Sort_Group
Output file name. Default (NULL) will generate a file name based on the data and time (e.g., MetricValuesGroups_bugs_20220201.xlsx)
Saves Excel file with metrics grouped by worksheet
This function will save the output of metric.values() into groups by worksheet as defined by the user.
The Excel file MetricNames.xlsx provided in the extdata folder has a column named 'Groups' that can be used as default groupings. If no groupings are provided (the default) all metrics are saved to a single worksheet. Within each group the 'sort_order' is used to sort the metrics. If this column is blank then the metrics are sorted in the order they appear in the output from metric.values() (i.e., in fun.DF).
The MetricNames data frame must include the following fields:
* Metric_Name
* Community
* Sort_Group (user defined)
# Example 1, bugs
## Community
comm <- "bugs"
## Calculate Metrics
df_metval <- metric.values(data_benthos_PacNW, comm)
#> Joining with `by = join_by(SAMPLEID, INDEX_NAME, INDEX_CLASS)`
## Metric Names and Groups
df_metnames <- readxl::read_excel(system.file("extdata/MetricNames.xlsx"
, package="BioMonTools")
, guess_max = 10^6
, sheet = "MetricMetadata"
, skip = 4)
## Columns to Keep
col2keep <- c("SAMPLEID", "INDEX_NAME", "INDEX_CLASS")
## Grouping Column
col_Grp <- "Sort_Group"
## File Name
file_out <- file.path(tempdir(), paste0("MetValGrps_", comm, ".xlsx"))
## Run Function
metvalgrpxl(df_metval, df_metnames, comm, col2keep, col_Grp, file_out)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example 2, fish
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example 2, periphyton (algae)