bindx | R Documentation |
Utilities for binding objects with inconsistent dimensions.
bind_all(..., which)
cbindx(..., deparse.level = 1L)
rbindx(..., deparse.level = 1L)
rbindfill(...)
rbindfill2(..., use.rownames = FALSE)
rbindlist(..., use.rownames = FALSE, use.names = FALSE)
rbindlist2(
data,
column,
split = "\\W+",
fixed = FALSE,
perl = FALSE,
use.rownames = any(rownames(data) != seq.int(nrow(data)))
)
... |
for |
which |
joining method; |
deparse.level |
integer controlling the construction of labels in
the case of non-matrix-like arguments (for the default method): |
use.rownames |
logical; for for |
use.names |
logical; if |
data |
a matrix or data frame |
column |
for |
split , fixed , perl |
arguments passed to |
bind_all
and rbindfill
are used for binding vectors,
the latter specifically for rbind
ing named vectors
a la a "stacking" merge.
cbindx
and rbindx
take vector-, matrix-, and data frame-like
objects and bind normally, filling with NA
s where dimensions are
not equal.
rbindfill
stacks named vectors by initializing a matrix
with all names and filling with ...
by row in the order given.
The column names will be a vector of the unique names in the order they
were given.
rbindfill2
row-binds data frames with zero or more common column
names. rbindfill2
starts with the first data frame given and
rbind
s subsequent data frames adding new columns of NA
as
needed to bind. Any columns with matching names will be aggregated;
otherwise, data frames without a matching column of data will be filled
with NA
.
rbindlist
converts a list of vectors into a long data frame with
two columns: the list index where each value was stored and the values
themselves. A third column will be added if use.names = TRUE
which
will keep the names of each vector.
rbindlist2
uses rbindlist
to expand data frames with one or
more nested columns.
cbind
; rbind
; interleave
;
clist
; qpcR
bind_all(1:5, 1:3, which = 'cbind')
bind_all(1:5, 1:3, which = 'rbind')
m1 <- matrix(1:4)
m2 <- matrix(1:4, 1)
cbindx(m1, m2)
rbindx(m1, m2)
rbindx(mtcars, m2)
## "stack" named vectors
f <- function(x) setNames(letters[x], LETTERS[x])
x <- lapply(list(1:5, 3:6, 2:7, 26), f)
do.call('rbindfill', x)
## "stack" matrices or data frames
colnames(m1) <- 'B'
colnames(m2) <- LETTERS[1:4]
rbindfill2(m1, m2)
rbindfill2(m2, m1)
set.seed(1)
dd <- matrix(NA, nrow = 1, ncol = 10)
dd <- as.data.frame(col(dd))
l <- setNames(lapply(1:5, function(x) dd[, sample(x), drop = FALSE]),
letters[1:5])
Reduce('rbindfill2', l) ## or do.call('rbindfill2', l)
do.call('rbindfill2', c(l, use.rownames = TRUE))
rbindfill2(l$c, l$e)
rbindfill2(head(mtcars), head(cars))
## "stack" a list of vectors with differing lengths
rbindlist(1:5)
rbindlist(1:5, 1:5)
l <- lapply(1:4, sequence)
rbindlist(l)
rbindlist(l[4L])
names(l) <- LETTERS[1:4]
rbindlist(l)
rbindlist(l[4L])
l <- lapply(l, function(x) setNames(x, letters[x]))
rbindlist(l, use.names = TRUE)
rbindlist(unname(l), use.names = TRUE)
## unnest and stack a data frame or matrix
dd <- data.frame(
id = 1:4, x = rnorm(4), y = sapply(l, toString),
z = sapply(l, paste, collapse = '...')
)
rbindlist2(dd, 'y')
## rownames are kept if data contains non default rownames
rbindlist2(`rownames<-`(dd, letters[1:4]), 'y')
## multiple columns can be expanded sequentially
rbindlist2(dd, c('y', 'z'))
rbindlist2(dd, 'y', split = '\\W+(?![^3]+3)', perl = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.