seqduplicated {divDyn} | R Documentation |
seqduplicated()
The function determines which elements of a vector are duplicates (similarly to duplicated
) in consecutive rows.
collapse()
Omits duplicates similarly to unique
, but only in consecutive rows, so the sequence of state changes remains, but without duplicates.
seqduplicated(x, na.rm = FALSE, na.breaks = TRUE) collapse(x, na.rm = FALSE, na.breaks = TRUE)
x |
( |
na.rm |
( |
na.breaks |
( |
These functions are essentially about checking whether a value in a vector at index is the same as the value at the previous index. This seamingly primitive task had to be rewritten with Rcpp for speed and the appropriate handling of NA
values.
# example vector examp <- c(4,3,3,3,2,2,1,NA,3,3,1,NA,NA,5, NA, 5) # seqduplicated() seqduplicated(examp) # contrast with duplicated(examp) # with NA removal seqduplicated(examp, na.rm=TRUE) # the same with collapse() collapse(examp) # contrast with unique(examp) # with NA removal collapse(examp, na.rm=TRUE) # with NA removal, no breaking collapse(examp, na.rm=TRUE, na.breaks=FALSE)