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, geometry = TRUE, use.na = FALSE)

Arguments

ref

An sf object that serves as a master list of features

key

Name of geographic id variable in the ref object to match input values to

clusters

A tibble created by qm_combine with two or more clusters worth of data

category

Value of the CAT variable to be analyzed

geometry

A logical scalar that returns the full geometry and attributes of ref when TRUE (default). If FALSE, only the key and count of features is returned after validation.

use.na

A logical scalar that returns NA values in the count variable if a feature is not included in any clusters when TRUE. If FALSE (default), a 0 value is returned in the count variable for each feature that is not included in any clusters. This parameter only impacts output if the geometry argument is TRUE.

Value

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.

See also

qm_combine

Examples

# 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") class(positive1)
#> [1] "sf" "data.frame"
mean(positive1$positive)
#> [1] 0.05660377
# summarize cluster objects with NA's instead of 0's positive2 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", use.na = TRUE) class(positive2)
#> [1] "sf" "data.frame"
mean(positive2$positive, na.rm = TRUE)
#> [1] 1.2
# return tibble of valid features only positive3 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive", geometry = FALSE) class(positive3)
#> [1] "tbl_df" "tbl" "data.frame"
mean(positive3$positive)
#> [1] 1.2