matrix.shift.bounds: Remaining bounds after shifting two matrices against each...

Description Usage Arguments Details Value Examples

View source: R/advanced.matrix.functions.R

Description

Determine the indices that limit the remainig matrix after shifting two matrices against each other.

Usage

1
matrix.shift.bounds(dimbase, dimshift, rowshift, colshift)

Arguments

dimbase

Dimension of static matrix, as returned by dim.

dimshift

Dimension of shifted matrix, as returned by dim.

rowshift

integer. column shift. See details.

colshift

integer. row shift. See details.

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.

Value

vector of bounds in the following order:

Examples

 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!

nobodyinperson/matrixutils documentation built on May 23, 2019, 9:31 p.m.