This is a convenience function for making data.frame
s that are easily
indexed on a block-wise basis.
block.data.frame(X, block_inds = NULL, to.matrix = TRUE)
Either a single data.frame
to index or a list
of matrices/data.frames
Named list
of indexes if X
is a single data.frame
, otherwise NULL
.
logical
indicating if input list elements should be converted to matrices.
A data.frame
which can be indexed block-wise.
# Random data
M <- matrix(rnorm(200), nrow = 10)
# .. with dimnames
dimnames(M) <- list(LETTERS[1:10], as.character(1:20))
# A named list for indexing
inds <- list(B1 = 1:10, B2 = 11:20)
X <- block.data.frame(M, inds)
str(X)
#> List of 2
#> $ B1: 'AsIs' num [1:10, 1:10] -0.991 -0.178 -1.713 -2.093 -0.514 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:10] "A" "B" "C" "D" ...
#> .. ..$ : chr [1:10] "1" "2" "3" "4" ...
#> $ B2: 'AsIs' num [1:10, 1:10] 1.1389 1.4999 -0.1757 -0.2967 -0.0221 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:10] "A" "B" "C" "D" ...
#> .. ..$ : chr [1:10] "11" "12" "13" "14" ...