repetition | R Documentation |
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.
repetition(
formula,
data,
format = "factor",
keep.time = TRUE,
sep = c(":", ".")
)
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 ( |
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 |
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). |
A numeric/character/factor vector, depending on argument format
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.