# collapse: Determination and omission of consecutive duplicates in a... In divDyn/r_package: Diversity Dynamics using Fossil Sampling Data

## Description

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.

## Usage

 1 2 3 seqduplicated(x, na.rm = FALSE, na.breaks = TRUE) collapse(x, na.rm = FALSE, na.breaks = TRUE)

## Arguments

 x (vector): input object. na.rm (logical): Are NA entries to be treated as duplicates (TRUE) or just like a normal value (FALSE)? na.breaks (logical): If na.rm=TRUE and the NA values are surrounded by the same values, should the streak be treated as broken? Running seqduplicated(, na.rm=TRUE) on (2, 1,NA, 1) while setting na.breaks to TRUE will return (FALSE, FALSE, TRUE, FALSE), and with TRUE it will return (FALSE, FALSE, TRUE, TRUE). The results with the same argumentation of collapse() will be (2,1) and (2,1,1).

## Details

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.

## Examples

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 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)

divDyn/r_package documentation built on July 9, 2019, 2:43 a.m.