count_if: Count the occurences in a vector

Description Usage Arguments Value Author(s) See Also Examples

Description

This function counts the occurences of a condition within a vector

Usage

1

Arguments

vector

The vector to count the occurences

condition

The condition to test the vector against

It must be a function

Value

The count of ocurrences in vector based on the condition

Author(s)

zekrom_vale

See Also

count_when for using str_detect to test a vector

count_if for using conditions to test a vector

count_if for counting using a dataframe or tibble, this has access to all columns

regex

str_detect

Examples

1
2
3
4
5
6
7
count_if(c("1","2","b","c","Z"), function(x)x=="2")
# Returns 1, counting the ones equal to "2"

count_if(c("1","2","b","c","Z"), function(x)str_detect(x,"\w"))
# Returns 3 as it is counting the values that match \w

count_if(1:100, function(x)x>50)

zekrom-vale/zUtil.R documentation built on June 2, 2019, 10:57 p.m.