collapse: Collapse a data frame

Description Usage Arguments Details Value Warning Examples

Description

Collapse unchanging consecutive observations for a given data frame.

Usage

1
collapse(data, include_na = FALSE)

Arguments

data

A data.frame. Data to collapse

include_na

Boolean. Whether to collapse consecutive NAs.

Details

If the given data frame contains multiple columns, then an observation is only collapsed if all of the columns are unchanging.

1
2
     Row and column names will be preserved; however, other
     user defined attributes will be dropped.

Value

A data.frame of row size: 0 < N <= nrow(data).

Warning

collapse currently only works with REALSXP, INTSXP, STRSXP, LGLSXP objects. This covers all of the common atomic R data types, including more complex types like Date. Unfortunately however, this means that collapse will return an error if a column has a class of raw. Bummer.

Examples

1
2
3
4
5
x <- data.frame(x = c(1, 1, 1), y = c(1, 2, 2))
collapse(x)

y <- data.frame(x = c(1, 1, 1), y = c("a", "a", "b"), stringsAsFactors = FALSE)
collapse(y)

jsks/seqR documentation built on May 9, 2019, 12:48 p.m.