Summary statistics of factor variable in a hypecSpec object by ID

count_spectra(
  OBJ,
  Var = NULL,
  ID = "ID",
  decimals = 1,
  include_na = TRUE,
  na_level = "(Missing)",
  na.rm = TRUE,
  total = FALSE
)

Arguments

OBJ

hyperSpec object

Var

(string) variable name of factor variable

ID

(string) variable name of ID variable

decimals

(integer) number of decimals to round to calculating the percentages. Default is 2.

include_na

(logical) If TRUE, NA values are included.

na_level

(character) Name for the level, which represents NA value.

na.rm

(logical) used by function sum(). Default is TRUE.

FALSE

(logical) Add row with "total".

Value

a data frame with counts and percentages by group and ID

See also

Other count spectra functions: has_enough_IDs(), has_too_few_IDs()

Examples


count_spectra(Spectra2, "class", ID = "gr")
#> Warning: Function 'chk.hy' is deprecated. 
#> Use function 'assert_hyperSpec' instead.
#> Warning: `fct_explicit_na()` was deprecated in forcats 1.0.0.
#>  Please use `fct_na_value_to_level()` instead.
#>  The deprecated feature was likely used in the spHelper package.
#>   Please report the issue to the authors.
#>    n_ID n_spectra percent_ID percent_spectra
#> K     3        50      25.0%           33.3%
#> l     3        30      25.0%           20.0%
#> N     3        19      25.0%           12.7%
#> S1    3        51      25.0%           34.0%
count_spectra(OBJ = Spectra2, Var = "class", ID = "gr")
#> Warning: Function 'chk.hy' is deprecated. 
#> Use function 'assert_hyperSpec' instead.
#>    n_ID n_spectra percent_ID percent_spectra
#> K     3        50      25.0%           33.3%
#> l     3        30      25.0%           20.0%
#> N     3        19      25.0%           12.7%
#> S1    3        51      25.0%           34.0%