group_prog_id: Group progressive id creator

View source: R/data_management.R

group_prog_idR Documentation

Group progressive id creator

Description

Starting from a vector of group id, this function creates a progressive id inside each group. It uses C for efficiency

Usage

group_prog_id(group)

Arguments

group

a group vector

Examples

set.seed(1)

## One factor id
x <- sample(c(rep("A",5), rep("C",3), rep("B",2), rep(NA,2)))
data.frame(group = x, id = group_prog_id(x) )

## Two factors id
y <- sample(gl(2,6, labels = c("C","D")))
data.frame(group1 = x, group2 = y, id = group_prog_id(interaction(x,y)) )

## example of sorting
db <- data.frame("group" = sample(gl(2,5)), "b" = Sys.Date() + 1:10)
db <- db[order( - as.integer(db$group), db$b),]
data.frame(db, id = group_prog_id(db$group))

lbraglia/lbmisc documentation built on March 28, 2024, 10:03 a.m.