downsize_matrix: Reducing the Size of a Matrix

Description Usage Arguments Details Value Note Examples

View source: R/downsize_matrix.R

Description

This function reduces the size of a matrix by picking one component from every k1 components in each row and one component from every k2 components in each column of the input matrix, and use the selected elements to construct a reduced matrix, where k1 and k2 are specified by "RowSample" and "ColSample", respectively.

Usage

1
downsize_matrix(M, RowSample = 1, ColSample = 1)

Arguments

M

the original input matrix.

RowSample

a positive integer for the rows. Select one component from every RowSample components. For example, RowSample = 2 means you select the 1st, 3rd, ... element from each row of the original matrix to construct your new matrix.

ColSample

a positive integer for the columns. Select one component from every ColSample components. For example, ColSample = 2 means you select the 1st, 3rd, ... element from each column of the original matrix to construct your new matrix.

Details

This function can be used to reduce the size of a matrix by picking sample elements of the original matrix as the elements of the reduced matrix. For example, "RowSample = 2", and "ColSample = 2" reduce the original size of a matrix to a quarter.

Value

the reduced matrix.

Note

This function is different from another function in this package called "downsize( )". That function is used to reduce the size of 3-D arrays while this function, downsize_matrix( ), is used to reduce the size of matrices.

Examples

1
2
3
4
5
6
#read the red band of an RGB image
library(png)
image = readPNG(system.file("extdata", "image1.png",
                             package = "implant",
                             mustWork = TRUE))[ , ,1]
downsize_matrix(M = image, RowSample = 2, ColSample = 2)

rwang14/implant documentation built on Sept. 6, 2020, 3:21 a.m.