Skip to contents

Get term frequencies of values in one vector x categorized by another vector by.

Usage

get_tf_by(x, by)

Arguments

x

A vector, such as a column of character strings

by

A vector of categories, such as a column of document identifiers

Value

A vector of term frequencies for each value pair of x and by.

See also

Examples

my_values <- c(
  "the", "cat", "was", "bad",
  "the", "dog", "was", "very", "good",
  "the", "lizard", "is", "the", "most", "bad")
my_docs <- c(
  "A", "A", "A", "A",
  "B", "B", "B", "B", "B",
  "C", "C", "C", "C", "C", "C")

get_tf_by(my_values, my_docs)
#>  [1] 0.2500000 0.2500000 0.2500000 0.2500000 0.2000000 0.2000000 0.2000000
#>  [8] 0.2000000 0.2000000 0.3333333 0.1666667 0.1666667 0.3333333 0.1666667
#> [15] 0.1666667