Description Usage Arguments Details Value Examples
View source: R/advanced.matrix.functions.R
Determine the indices that limit the remainig matrix after shifting two matrices against each other.
1 | matrix.shift.bounds(dimbase, dimshift, rowshift, colshift)
|
dimbase |
Dimension of static matrix, as returned by |
dimshift |
Dimension of shifted matrix, as returned by |
rowshift |
integer. column shift. See details. |
colshift |
integer. row shift. See details. |
Imagine two matrices mshift
and mbase
. You shift matrix mshift
against mbase
by
a certain amount of rows and columns. Now you have a remaining
matrix that is possibly smaller than mshift
or mbase
. The bounds of this
remaining matrix are in both matrices.
This function returns only the bounds of the matrices mshift
and mbase
that limit the remainig matrix.
The rowshift
and colshift
parameters describe the shifts in units of rows and columns respectively.
A positive value indicates an downwards (!) / rightwards shift of matrix m1
against m2
.
A negative value indicates a upwards (!) / leftwards shift. Values greater than
the respective dimensions dim
lead to indefinite bounds because there
is no remaining matrix after shifting. In this case, all bounds are set to NA
.
vector of bounds in the following order:
mirosh
: lower rowbound of mshift
marosh
: upper rowbound of mshift
micosh
: lower columnbound of mshift
macosh
: upper columnbound of mshift
miroba
: lower rowbound of mbase
maroba
: upper rowbound of mbase
micoba
: lower columnbound of mbase
macoba
: upper columnbound of mbase
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Two equal 3x3-matrices
(m1 <- m2 <- matrix(1:9,3,3))
# [,1] [,2] [,3]
# [1,] 1 4 7
# [2,] 2 5 8
# [3,] 3 6 9
# Shift by 0 rows and 0 columns
(bounds = matrix.shift.bounds(dim(m1),dim(m2),0,0))
# [1] 1 3 1 3 1 3 1 3
# Remaining part of m1:
m1[bounds[1]:bounds[2],bounds[3]:bounds[4]]
# [,1] [,2] [,3]
# [1,] 1 4 7
# [2,] 2 5 8
# [3,] 3 6 9
# Everything! Because nothing was shifted!
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.