counting_events_group: Counts events

Description Usage Arguments Value Examples

View source: R/counting_events_group.R

Description

creates a data.frame counting occurencies of specific events in a given vector separated by named connex groups. For example it allows to count occurencies of each category of a qualitative variable above in the dataset for each individual. Grouping allows to reset the count each time another variable changes.

The idea is to create a cumulative history of what happened before current individual.

One new variable is created for each unique value of events

Usage

1
2
3
4
5
6
7
8
9
counting_events_group(
  events = events,
  group = NULL,
  base = NULL,
  prefix = NULL,
  suffix = NULL,
  clean = TRUE,
  keep = FALSE
)

Arguments

events

The vector of events to count (qualitative values). One new variable is created for each unique value of events.

group

qualitative vector that resets counting when its value changes.

base

a dataframe to which counting can be added (cbind).

prefix

(optional) prefix to the newly created variables names

suffix

(optional) suffix to the newly created variables names

clean

(boolean) to decide either or not variables names has to be cleaned (spaces, accents and special characters)

keep

(boolean) to decide either or not events and group are to be added to the resulting data.frame

Value

a data.frame which number of rows is the length of events

Examples

1
2
3
events <- rep(c('a', 'b', 'c'), times = 20)
group <- rep(rep(c('A', 'B'), c(12, 8)), times = 3)
counting_events_group(events, group)

CorReg-community/CorReg documentation built on Oct. 19, 2021, 6:30 p.m.