R/rowAlls.R
rowAlls.RdChecks if a value exists / does not exist in each row (column) of a matrix.
rowAlls(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
dim. = dim(x), ..., useNames = TRUE)
colAlls(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
dim. = dim(x), ..., useNames = TRUE)
allValue(x, idxs = NULL, value = TRUE, na.rm = FALSE, ...)
rowAnys(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
dim. = dim(x), ..., useNames = TRUE)
colAnys(x, rows = NULL, cols = NULL, value = TRUE, na.rm = FALSE,
dim. = dim(x), ..., useNames = TRUE)
anyValue(x, idxs = NULL, value = TRUE, na.rm = FALSE, ...)A vector indicating subset of rows to
operate over. If NULL, no subsetting is done.
A vector indicating subset of columns to
operate over. If NULL, no subsetting is done.
A value to search for.
If TRUE, missing values are
excluded.
An integer vector of
length two specifying the dimension of x, also when not a
matrix. Comment: The reason for this argument
being named with a period at the end is purely technical (we get a run-time
error if we try to name it dim).
Not used.
If TRUE (default), names
attributes of the result are set, otherwise not.
A vector indicating subset of elements to
operate over. If NULL, no subsetting is done.
rowAlls() (colAlls()) returns an
logical vector of length N (K).
Analogously for rowAnys() (rowAlls()).
These functions takes either a matrix or a vector as input. If a vector,
then argument dim. must be specified and fulfill prod(dim.) ==
length(x). The result will be identical to the results obtained when
passing matrix(x, nrow = dim.[1L], ncol = dim.[2L]), but avoids
having to temporarily create/allocate a matrix, if only such is needed
only for these calculations.
valueWhen value is logical, the result is as if the function is applied
on as.logical(x). More specifically, if x is numeric, then
all zeros are treated as FALSE, non-zero values as TRUE,
and all missing values as NA.
rowCounts
x <- matrix(FALSE, nrow = 10, ncol = 5)
x[3:7, c(2, 4)] <- TRUE
x[2:4, ] <- TRUE
x[, 1] <- TRUE
x[5, ] <- FALSE
x[, 5] <- FALSE
print(x)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] TRUE FALSE FALSE FALSE FALSE
#> [2,] TRUE TRUE TRUE TRUE FALSE
#> [3,] TRUE TRUE TRUE TRUE FALSE
#> [4,] TRUE TRUE TRUE TRUE FALSE
#> [5,] FALSE FALSE FALSE FALSE FALSE
#> [6,] TRUE TRUE FALSE TRUE FALSE
#> [7,] TRUE TRUE FALSE TRUE FALSE
#> [8,] TRUE FALSE FALSE FALSE FALSE
#> [9,] TRUE FALSE FALSE FALSE FALSE
#> [10,] TRUE FALSE FALSE FALSE FALSE
print(rowCounts(x)) # 1 4 4 4 0 3 3 1 1 1
#> [1] 1 4 4 4 0 3 3 1 1 1
print(colCounts(x)) # 9 5 3 5 0
#> [1] 9 5 3 5 0
print(rowAnys(x))
#> [1] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE
print(which(rowAnys(x))) # 1 2 3 4 6 7 8 9 10
#> [1] 1 2 3 4 6 7 8 9 10
print(colAnys(x))
#> [1] TRUE TRUE TRUE TRUE FALSE
print(which(colAnys(x))) # 1 2 3 4
#> [1] 1 2 3 4