remove_duplicated_states {cfda}R Documentation

Remove duplicated states

Description

Remove duplicated consecutive states from data. If for an individual there is two or more consecutive states that are identical, only the first is kept. Only time when the state changes are kept.

Usage

remove_duplicated_states(data, keep.last = TRUE)

Arguments

data

data.frame containing id, id of the trajectory, time, time at which a change occurs and state, associated state.

keep.last

if TRUE, keep the last state for every individual even if it is a duplicated state.

Value

data without duplicated consecutive states

Author(s)

Quentin Grimonprez

See Also

Other format: convertToCfd(), cut_data(), matrixToCfd()

Examples

data <- data.frame(
  id = rep(1:3, c(10, 3, 8)), time = c(1:10, 1:3, 1:8),
  state = c(rep(1:5, each = 2), 1:3, rep(1:3, c(1, 6, 1)))
)
out <- remove_duplicated_states(data)

[Package cfda version 0.11.0 Index]