ez.countif | R Documentation |
count within one or more than one columns/rows, or entire data frame (ie, all columns/rows)
ez.countif(x, cnd, col = NULL, dim = 3, na.rm = FALSE)
x |
data frame or vector, if vector, parameters col, dim are ignored |
col |
column evaluated by eval('dplyr::select()'), single or vector. If NULL, all columns used |
dim |
1=along row (rowwise), 2=along col (colwse), 3=area, both, grand total (within specified cols/rows) |
cond |
a string like '.>=3', '.=="M"', 'is.na(.)', 'ifelse()'
|
returns a data frame, if dim=1/2; a single value if dim=3.
vector input x always outputs a single value.
ez.countif
sx = c("F", "F", "F", "M", "M", "M")
ht = c(69, 64, 67, 68, 72, 71)
wt = c(148, 132, 142, 149, 167, 165)
people = data.frame(sx, ht, wt)
ez.countif(people,'.=="M"','wt', dim=2) # wt 0
ez.countif(people,'.>150', dim=2) # sx ht wt NA 0 2
ez.countif(people$wt, '.==165')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.