repetition: Number of Repetitions Within Cluster

View source: R/repetition.R

repetitionR Documentation

Number of Repetitions Within Cluster

Description

Create a vector containing, for each line of the dataset, the number of occurences of the corresponding cluster up to the current line. Can stratify the number of occurences on one or several variables.

Usage

repetition(
  formula,
  data,
  format = "factor",
  keep.time = TRUE,
  sep = c(":", ".")
)

Arguments

formula

[formula] Specify the structure of the data: the time/repetition variable and the grouping variable, e.g. ~1|id, ~ time|id, or ~time+region|id.

data

[data.frame] dataset containing the observations.

format

[character] the type of the output: a numeric vector ("numeric"), a character vector ("character"), or a factor vector ("factor").

keep.time

[logical] should the value of the time variable at the repetition be kept in the output (e.g. baseline.1, baseline.2, followUp.1 instead of 1,2,3). Only relevant when argument formula contain a time/repetition variable and format="character" or format="factor".

sep

[character vector of length 2] character strings used to combine time variables (first element) and the name of the time variable with its values (second element).

Value

A numeric/character/factor vector, depending on argument format.

Examples

data(sleepL, package = "LMMstar")
sleepL$dday <- paste0("d",sleepL$day)
sleepL$rep <- repetition(~1|id, data = sleepL)
sleepL$repDay <- repetition(~dday|id, data = sleepL)
sleepL$repDay.num <- repetition(~dday|id, data = sleepL, format = "numeric")
head(sleepL,15)

bozenne/repeated documentation built on July 16, 2025, 11:16 p.m.