qm_summarize | R Documentation |
This function creates a column that contains a single observation for each unique value in the key variable. For each feature, a count corresponding to the number of times that feature is identified in a cluster for the give category is also provided.
qm_summarize(ref, key, clusters, category, count, geometry = TRUE, use.na = FALSE)
ref |
An |
key |
Name of geographic id variable in the |
clusters |
A tibble created by |
category |
Value of the |
count |
How should clusters be summarized: by counting each time a feature is included
in a cluster ( |
geometry |
A logical scalar that returns the full geometry and attributes of |
use.na |
A logical scalar that returns |
A tibble or a sf
object (if geometry = TRUE
) that contains a count of the number
of clusters a given feature is included in. The tibble option (when geometry = FALSE
) will only
return valid features. The sf
option (default; when geometry = TRUE
) will return all
features with either zeros (when use.na = FALSE
) or NA
values (when use.na = TRUE
)
for features not included in any clusters.
qm_combine
# load and format reference data stl <- stLouis stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE)) # create clusters cluster1 <- qm_define(118600, 119101, 119300) cluster2 <- qm_define(119300, 121200, 121100) # create cluster objects cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1, rid = 1, cid = 1, category = "positive") cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2, rid = 1, cid = 2, category = "positive") # combine cluster objects clusters <- qm_combine(cluster_obj1, cluster_obj2) # summarize cluster objects positive1 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters") class(positive1) mean(positive1$positive) # summarize cluster objects with NA's instead of 0's positive2 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", use.na = TRUE) class(positive2) mean(positive2$positive, na.rm = TRUE) # return tibble of valid features only positive3 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "clusters", geometry = FALSE) class(positive3) mean(positive3$positive) # count respondents instead of clusters positive4 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", count = "respondents") mean(positive4$positive)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.