Skip to contents

Get dictionary matches of values in a vector

Usage

get_match(x, dictionary, keep = NULL)

Arguments

x

A vector, such as a column of character strings

dictionary

A data frame with two or more columns, potentially made with make_dictionary().

keep

The number of matched values to keep. If NULL, returns all matched values in a nested list.

Value

A vector or nested list of sentiments for each value of x.

See also

Examples

my_values <- c("It", "is", "raining")

emoji_weather <- make_dictionary(
  list(
    "️☔️" = c("rain", "rains", "rainy", "raining"),
    "️⛈️" = c("storm", "storms", "stormy", "storming"),
    "☁️" = c("cloud", "clouds", "cloudy"),
    "🌞" = c("sun", "sunny"),
    "🌫️" = c("fog", "fogs", "foggy", "mist", "misty"),
    "🌬️" = c("wind", "winds", "windy"),
    "️❄️" = c("snow", "snows", "snowing")),
  name = "weather")

get_match(my_values, emoji_weather)
#> [1] NA   NA   "️☔️"