freq: Computing frequencies of elements in a vector.

Description Usage Arguments Value See Also Examples

Description

Computes number of occurrences of specified elements in a vector. This function behaves slightly different than R base function table, since we specify the elements, frequency of elements that were not found will be reported as zero. See also http://stackoverflow.com/questions/1923273/counting-the-number-of-elements-with-the-values-of-x-in-a-vector

Usage

1
freq(x, elts)

Arguments

x

A numeric vector that we wish to check how many times elements specified in elts appear.

elts

A vector with elements that we wish to count in vector x.

Value

A numeric vector of the same length as elts, with names elements.

See Also

table which is very similar

Examples

1
2
3
4
5
6
# create some test data
x <- rep(1:3, 4)
elts <- c(1, 2, 4)

# get the counts of specified elements 
freq(x, elts)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.