Attaches covariates, such as habitat or elevation, to histories that were built without them. Rows are matched to the sites by name, so the order of your table does not matter.
Arguments
- x
A
pam_count_historyorpam_count_histories.- covariates
A data frame with a
site_idcolumn and one column per covariate. Every site ofxneeds a row; extra rows are ignored. Without asite_idcolumn the table needs one row per site, in the order of the sites.- replace
If
FALSE(the default), a covariate that is already present is an error; ifTRUE, it is replaced.
Examples
counts <- matrix(c(0, 2, 5, 1, 0, 3), nrow = 3,
dimnames = list(c("site_a", "site_b", "site_c"), NULL))
hist <- pam_as_count_history(counts, species = "Example species")
covs <- data.frame(site_id = c("site_c", "site_a", "site_b"), canopy = c(0.9, 0.2, 0.5))
pam_add_site_covariates(hist, covs)$site_covariates
#> site_id canopy
#> 1 site_a 0.2
#> 2 site_b 0.5
#> 3 site_c 0.9
