data_each: Prepare data for a cluster

View source: R/model-within.R

data_eachR Documentation

Prepare data for a cluster

Description

Subset a spatio-temporal dataset for a cluster and convert it to a long format with indices for time and spatial location.

Usage

data_each(k, membership, stdata, stnames = c("geometry", "time"))

Arguments

k

The cluster number to subset.

membership

A vector defining the cluster membership for each region.

stdata

A stars object containing spatial-temporal dimensions defined in stnames.

stnames

The names of the spatial and temporal dimensions.

Value

A long-format data frame with ids for each observation and for spatial and time indexing.

Examples


library(sfclust)
library(stars)

dims <- st_dimensions(
  geometry = st_sfc(lapply(1:5, function(i) st_point(c(i, i)))),
  time = seq(as.Date("2024-01-01"), by = "1 day", length.out = 3)
)
stdata <- st_as_stars(cases = array(1:15, dim = c(5, 3)), dimensions = dims)

data_each(k = 2, membership = c(1, 1, 1, 2, 2), stdata)


sfclust documentation built on June 8, 2025, 10:11 a.m.