# count_vals_byname: Count the number of matrix entries that meet a criterion In matsbyname: An Implementation of Matrix Mathematics

 count_vals_byname R Documentation

## Count the number of matrix entries that meet a criterion

### Description

Expressions can be written in a natural way such as `count_vals_byname(m, "<=", 1)`.

### Usage

```count_vals_byname(
a,
compare_fun = c("==", "!=", "<", "<=", ">=", ">"),
val = 0
)
```

### Arguments

 `a` a matrix or list of matrices whose values are to be counted according to `compare_fun` `compare_fun` the comparison function, one of "`==`", "`!=`", "`<`", "`<=`", "`>`", or "`>=`". Default is "`==`". `val` the value against which matrix entries are compared. Default is `0`.

### Details

Either a single matrix or a list of matrices can be given as the `a` argument. `compare_fun` can be specified as a string (`"!="`) or as a back-quoted function (``!=``).

### Value

an integer indicating the number of entries in `a` that meet the specified criterion

### Examples

```m <- matrix(c(0, 1, 2, 3, 4, 0), nrow = 3, ncol = 2)
count_vals_byname(m) # uses defaults: compare_fun = "==" and val = 0
count_vals_byname(m, compare_fun = "!=")
count_vals_byname(m, compare_fun = `!=`)
# Write expressions in a natural way
count_vals_byname(m, "<=", 1)
# Also works for lists
count_vals_byname(list(m,m), "<=", 1)
```

matsbyname documentation built on April 2, 2022, 1:06 a.m.