R/structure_groups.R

Defines functions structure_groups

Documented in structure_groups

#' @title Structure Groups
#' @description Creates a named list of sequential integer groups.
#' @param names Character vector of group names.
#' @param values Integer vector of group sizes.
#' @return A named list of integer sequences.
#' @export
#' @examples
#' # Two scales: the first four items and the next five
#' structure_groups(c("Anxiety", "Depression"), c(4, 5))
structure_groups <- function(names, values) {
  if(length(names) != length(values)) {
    stop("The length of names and values must be the same.")
  }

  groups_list <- list()

  start <- 1
  for(i in seq_along(names)) {
    end <- start + values[i] - 1
    groups_list[[names[i]]] <- seq(start, end)
    start <- end + 1
  }

  groups <- structure(groups_list, Names = names)

  return(groups)
}

Try the InterconectaR package in your browser

Any scripts or data that you put into this service are public.

InterconectaR documentation built on Oct. 16, 2026, 1:06 a.m.