slide_matrix: Slide a matrix in a given direction

Description Usage Arguments Details Value

View source: R/mines.R

Description

Translates a matrix in a given direction (or directions)

Usage

1
slide_matrix(mat, directions, fill = NA, simplify = FALSE)

Arguments

mat

- the matrix to slide

directions

- a dataframe of the directions in which to slide the matrix, each row being the row-column coordinates of a direction vector (see details)

fill

- the value with which to fill empty space left from sliding the given matrix

simplify

- whether to merge results into a matrix or return a list of slidden matrices (see details)

Details

If simplify = TRUE, than this returns a matrix where each column is a matrix unrolled into a vector. If simplify = FALSE, this returns a list of matrices resulted from sliding the given matrix in given directions.

Directions should be a dataframe with columns named 'row' and 'col' and each row in the dataframe is a row-col vector which gives the direction for translation. If 'row' and 'col' aren't the names of columns, the first column in the dataframe will be treated as 'row' and the second as 'col'.

If only one direction is given, it needn't be a dataframe, but can be just a vector with row-col coordinates.

Value

Matrix (or list of matrices) which represent mat translated in given direction(s). See details.


Blaza/ssoftveR documentation built on May 6, 2019, 11:19 a.m.