is_off_diag: is_off_diag

View source: R/is_off_diag.R

is_off_diagR Documentation

is_off_diag

Description

This function tests an input matrix and returns a logical matrix of the same dimensions, with TRUE indicating that a cell is in the desired off-diagonal. By default, the function returns the sub-diagonal (i.e., the lower off-diagonal).

Usage

is_off_diag(.dat, .off_diag = 1, sub_diag = TRUE)

Arguments

.dat

A matrix or dataframe.

.off_diag

A numeric scalar. NROW(.dat) - .off_diag must be greater than or equal to 1. If a negative value is entered, the absolute value will be taken. If .off_diag = 0, the primary matrix diagonal is identified. Defaults to 1.

sub_diag

Logical. Indicates whether the sub-diagonal (lower off-diagonal) or the super-diagonal (upper off-diagonal) should be identified. If sub_diag = TRUE, the sub-diagonal will be identified, if sub_diag = FALSE, the super-diagonal will be returned instead. Defaults to TRUE.

Value

This function returns a logical matrix with the same dimensions as .dat. All cells but those lying on the desired off-diagonal will take the value of FALSE, while those on the off-diagonal will return a value of TRUE.

Examples

## Not run: 

nr <- 4
nc <- 6

mat <- matrix(seq(4*6), nrow = nr, ncol = nc)
df <- as.data.frame(mat)

# works for matrices
is_off_diag(mat, .off_diag = 2)
is_off_diag(mat, .off_diag = 2, sub_diag = F)

# and dataframes
is_off_diag(df, .off_diag = 2)
is_off_diag(df, .off_diag = 2, sub_diag = F)

# check for equality
all(is_off_diag(mat, 2) == is_off_diag(df, 2))
all(is_off_diag(mat, 2, sub_diag = F) == is_off_diag(df, 2, sub_diag = F))


## End(Not run)

tessaleejohnson/corclus documentation built on Oct. 11, 2022, 3:46 a.m.