cbind2 {methods} | R Documentation |
Combine two “matrix-like” R objects by columns (cbind2
)
or rows (rbind2
). These are (S4) generic functions with default
methods.
cbind2(x, y) rbind2(x, y)
x |
any R object, typically “matrix-like”. |
y |
any R object, typically similar to x , or missing
completely. |
The main use of cbind2
(rbind2
) is to be called by
cbind()
(rbind()
)
if these are activated. This allows cbind
(rbind
) to “work” for formally classed (aka ‘S4’)
objects by providing S4 methods for these objects. Currently, a call
methods:::bind_activation(TRUE)
is needed to install a
“cbind2
-calling” version of cbind
(into the
base
namespace) and the same for rbind
.
methods:::bind_activation(FALSE)
reverts to the
previous internal version of cbind
which does not build on
cbind2
, see the examples.
A matrix (or matrix like object) combining the columns (or rows) of
x
and y
.
cbind2(1:3, 4) m <- matrix(3:8, 2,3, dimnames=list(c("a","b"), LETTERS[1:3])) cbind2(1:2, m) # keeps dimnames from m ### Note: Use the following activation if you want cbind() to work ### ---- on S4 objects -- be careful otherwise! methods:::bind_activation(on = TRUE) trace("cbind2") cbind(a=1:3)# no call to cbind2() cbind(a=1:3, four=4, 7:9)# calling cbind2() twice untrace("cbind2") ## The following fails currently, ## since cbind() works recursively from the tail: try( cbind(m, a=1, b=3) ) ## turn off the `special cbind()' : methods:::bind_activation(FALSE)