groupProgID: Group progressive id creator

Description Usage Arguments Examples

View source: R/groupProgID.R

Description

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

Usage

1

Arguments

group

a group vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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 = groupProgID(x) )

## Two factors id
y <- sample(gl(2,6, labels = c("C","D")))
data.frame(group1 = x, group2 = y, id = groupProgID(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 = groupProgID(db$group))

lbraglia/yapomif documentation built on May 20, 2019, 11:26 p.m.