Learn R Programming

cppcontainers (version 1.0.4)

count: Count element frequency

Description

Count how often elements occur in a container.

Usage

count(x, values)

Value

Returns a vector of the same length as values, denoting for each value how often it occurs.

Arguments

x

A CppSet, CppUnorderedSet, CppMultiset, CppUnorderedMultiset, CppMap, CppUnorderedMap, CppMultimap, or CppUnorderedMultimap object.

values

A vector of elements to check. Refers to keys in the case of CppMap, CppUnorderedMap, CppMultimap, and CppUnorderedMultimap objects.

See Also

[, ==, at, contains, size, empty.

Examples

Run this code
s <- cpp_set(4:9)
s
# 4 5 6 7 8 9

count(s, 9:11)
# [1] 1 0 0

m <- cpp_map(c("hello", "there"), c(1.2, 1.3))
m
# ["hello",1.2] ["there",1.3]

count(m, c("hello", "world"))
# [1] 1 0

Run the code above in your browser using DataLab