This function takes a dataframe containing text data and returns a dataframe with the `top_n` n-grams and their corresponding exemplars
Usage
ngram_exemplars(
df,
top_n = 50,
n = 2,
text_var = message,
url_var = permalink,
sentiment_var = sentiment,
date_var = date,
author_var = sender_screen_name,
platform_var = social_network
)
Arguments
- df
Data frame or tibble object
- top_n
Top n n-grams to output exemplars for
- n
value of n in n-gram e.g. 2 = bigram
- text_var
Name of your text variable
- url_var
Name of your url variable
- sentiment_var
Name of your sentiment variable
- date_var
Name of your date variable
Name of the author variable e.g. 'sender_screen_name'
- platform_var
Name of the platform variable e.g. 'social_network'
Examples
# Example data
test_data <- tibble::tibble(
message = c("This is a test message", "Another test message", "Yet another message"),
permalink = c("http://test1.com", "http://test2.com", "http://test3.com"),
sentiment = c("positive", "negative", "neutral"),
date = as.Date(c("2022-01-01", "2022-01-02", "2022-01-03"))
)
# Using ngram_exemplars function
result <- ngram_exemplars(test_data)