Skip to contents

Distinct values of `x` are put in sorted order and then grouped in blocks of `resolution`, so `resolution = 1` keeps every location separate and `resolution = 4` merges each run of four neighbouring codes into one cell.

Usage

coarsen_place(x, resolution = 1)

Arguments

x

location codes: any vector that can be sorted

resolution

number of neighbouring locations merged into one cell

Value

an integer vector of cell indices, one per element of `x`

Details

SORT ORDER IS TAKEN AS ADJACENCY. There is no geometry here, only labels, so "next to" has to mean "next in sort order". That is correct for codes built to have that property – mesh codes, geohashes, zero-padded antenna or shop ids – and wrong for arbitrary names, where it would merge unrelated locations and report a *lower* unicity than the data deserves. Pass an already-coarsened column with `resolution = 1` if your locations do not sort geographically.

Grouping is relative to the values actually present, not to an absolute grid, so two data sets with different location sets are not directly comparable at the same `resolution`.

Examples

coarsen_place(c("P001", "P002", "P003", "P004"), resolution = 2)
#> [1] 1 1 2 2