make_grouped_pagenums {clinify} | R Documentation |
Assign Page Numbers to Presorted Grouped Data
Description
Assigns sequential page numbers to elements of a vector, grouping by unique values and allocating a specified number of rows per page. The input vector must be presorted by group.
Usage
make_grouped_pagenums(var, rows)
Arguments
var |
A vector of group labels, presorted so that identical values are contiguous. |
rows |
Integer. The maximum number of rows per page. |
Details
The function splits the input vector into groups, then assigns page numbers within each group so that each page contains up to 'rows“ items. Page numbers increment sequentially across groups. If the input is not presorted by group, the function will throw an error.
Value
An integer vector of the same length as 'var“, indicating the assigned page number for each element.
Examples
library(dplyr)
iris |>
mutate(
page = make_grouped_pagenums(Species, 5)
)
[Package clinify version 0.3.0 Index]