Description Usage Arguments Value Author(s) See Also Examples
Extracts one cell per row (column) from a matrix. The implementation is optimized for memory and speed.
1 2 3 4 | ## S3 method for class 'matrix'
rowCollapse(x, idxs, ...)
## S3 method for class 'matrix'
colCollapse(x, idxs, ...)
|
x |
An NxK |
idxs |
An index |
... |
Not used. |
Returns a vector
of length N (K).
Henrik Bengtsson
Matrix indexing to index elements in matrices and arrays,
cf. [
().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | x <- matrix(1:27, ncol=3)
y <- rowCollapse(x, 1)
stopifnot(identical(y, x[,1]))
y <- rowCollapse(x, 2)
stopifnot(identical(y, x[,2]))
y <- rowCollapse(x, c(1,1,1,1,1,3,3,3,3))
stopifnot(identical(y, c(x[1:5,1], x[6:9,3])))
y <- rowCollapse(x, 1:3)
print(y)
yT <- c(x[1,1],x[2,2],x[3,3],x[4,1],x[5,2],x[6,3],x[7,1],x[8,2],x[9,3])
stopifnot(identical(y, yT))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.