rowbind {collapse}R Documentation

Row-Bind Lists / Data Frame-Like Objects

Description

collapse's version of data.table::rbindlist and rbind.data.frame. The core code is copied from data.table, which deserves all credit for the implementation. rowbind only binds lists/data.frame's. For a more flexible recursive version see unlist2d. To combine lists column-wise see add_vars or ftransform (with replacement).

Usage

rowbind(..., idcol = NULL, row.names = FALSE,
        use.names = TRUE, fill = FALSE, id.factor = "auto",
        return = c("as.first", "data.frame", "data.table", "tibble", "list"))

Arguments

...

a single list of list-like objects (data.frames) or comma separated objects (internally assembled using list(...)). Names can be supplied if !is.null(idcol).

idcol

character. The name of an id-column to be generated identifying the source of rows in the final object. Using idcol = TRUE will set the name to ".id". If the input list has names, these will form the content of the id column, otherwise integers are used. To save memory, it is advised to keep id.factor = TRUE.

row.names

TRUE extracts row names from all the objects in l and adds them to the output in a column named "row.names". Alternatively, a column name i.e. row.names = "variable" can be supplied.

use.names

logical. TRUE binds by matching column name, FALSE by position.

fill

logical. TRUE fills missing columns with NAs. When TRUE, use.names is set to TRUE.

id.factor

if TRUE and !isFALSE(idcols), create id column as factor instead of character or integer vector. It is also possible to specify "ordered" to generate an ordered factor id. "auto" uses TRUE if !is.null(names(l)) where l is the input list (because factors are much more memory efficient than character vectors).

return

an integer or string specifying what to return. 1 - "as.first" preserves the attributes of the first element of the list, 2/3/4 - "data.frame"/"data.table"/"tibble" coerces to specific objects, and 5 - "list" returns a (named) list.

Value

a long list or data frame-like object formed by combining the rows / elements of the input objects. The return argument controls the exact format of the output.

See Also

unlist2d, add_vars, ftransform, Data Frame Manipulation, Collapse Overview

Examples

# These are the same
rowbind(mtcars, mtcars)
rowbind(list(mtcars, mtcars))

# With id column
rowbind(mtcars, mtcars, idcol = "id")
rowbind(a = mtcars, b = mtcars, idcol = "id")

# With saving row-names
rowbind(mtcars, mtcars, row.names = "cars")
rowbind(a = mtcars, b = mtcars, idcol = "id", row.names = "cars")

# Filling up columns
rowbind(mtcars, mtcars[2:8], fill = TRUE)

[Package collapse version 2.0.13 Index]