is_off_diag | R Documentation |
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).
is_off_diag(.dat, .off_diag = 1, sub_diag = TRUE)
.dat |
A matrix or dataframe. |
.off_diag |
A numeric scalar. |
sub_diag |
Logical. Indicates whether the sub-diagonal (lower
off-diagonal) or the super-diagonal (upper off-diagonal) should be
identified. If |
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
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.