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.

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

See also

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

Author

Quentin Grimonprez

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)