title: “Text Analysis of Customer Comments” author: “Seth Billingsley” output: html_document —
This report analyzes five customer comments using tidy text analysis. The analysis splits the comments into individual words, removes common stop words, and counts the remaining words to identify frequently discussed topics.
Each row contains one customer comment.
comments <- tibble(
comment_id = 1:5,
text = c(
"I love the quality of this product. The price is reasonable, and delivery was fast.",
"The product quality is excellent, but the shipping took too long.",
"Great customer service! I would definitely recommend this product to my friends.",
"The price is too expensive. However, the product looks beautiful.",
"Fast delivery and excellent service. I am very satisfied with my purchase."
)
)
knitr::kable(comments)
| comment_id | text |
|---|---|
| 1 | I love the quality of this product. The price is reasonable, and delivery was fast. |
| 2 | The product quality is excellent, but the shipping took too long. |
| 3 | Great customer service! I would definitely recommend this product to my friends. |
| 4 | The price is too expensive. However, the product looks beautiful. |
| 5 | Fast delivery and excellent service. I am very satisfied with my purchase. |
The unnest_tokens() function creates one word per row. It also removes punctuation and converts words to lowercase.
tidy_comments <- comments %>%
unnest_tokens(word, text)
knitr::kable(head(tidy_comments, 20))
| comment_id | word |
|---|---|
| 1 | i |
| 1 | love |
| 1 | the |
| 1 | quality |
| 1 | of |
| 1 | this |
| 1 | product |
| 1 | the |
| 1 | price |
| 1 | is |
| 1 | reasonable |
| 1 | and |
| 1 | delivery |
| 1 | was |
| 1 | fast |
| 2 | the |
| 2 | product |
| 2 | quality |
| 2 | is |
| 2 | excellent |
Stop words are common words such as “the,” “and,” and “is.” Removing them helps highlight more informative words.
clean_comments <- tidy_comments %>%
anti_join(stop_words, by = "word")
knitr::kable(clean_comments)
| comment_id | word |
|---|---|
| 1 | love |
| 1 | quality |
| 1 | product |
| 1 | price |
| 1 | reasonable |
| 1 | delivery |
| 1 | fast |
| 2 | product |
| 2 | quality |
| 2 | excellent |
| 2 | shipping |
| 3 | customer |
| 3 | service |
| 3 | recommend |
| 3 | product |
| 3 | friends |
| 4 | price |
| 4 | expensive |
| 4 | product |
| 4 | beautiful |
| 5 | fast |
| 5 | delivery |
| 5 | excellent |
| 5 | service |
| 5 | satisfied |
| 5 | purchase |
This table shows how often each remaining word appears.
word_counts <- clean_comments %>%
count(word, sort = TRUE)
knitr::kable(word_counts)
| word | n |
|---|---|
| product | 4 |
| delivery | 2 |
| excellent | 2 |
| fast | 2 |
| price | 2 |
| quality | 2 |
| service | 2 |
| beautiful | 1 |
| customer | 1 |
| expensive | 1 |
| friends | 1 |
| love | 1 |
| purchase | 1 |
| reasonable | 1 |
| recommend | 1 |
| satisfied | 1 |
| shipping | 1 |
The chart displays words that appear at least twice.
word_counts %>%
filter(n >= 2) %>%
ggplot(aes(x = reorder(word, n), y = n)) +
geom_col(fill = "steelblue") +
coord_flip() +
scale_y_continuous(breaks = 0:4) +
labs(
title = "Most Frequent Words in Customer Comments",
x = "Word",
y = "Frequency"
) +
theme_minimal()
“Product” appears four times, while “quality,” “price,” “delivery,” “fast,” “excellent,” and “service” each appear twice. Reading the original comments alongside these counts shows praise for quality and service, with concerns about shipping time and price.
One challenge was figuring out how to split each comment into
individual words. I addressed this by using
unnest_tokens(word, text), which created one word per row
so I could count word frequencies.
This analysis uses only five comments, so the results cannot be generalized to all customers. Word counts also do not capture the full meaning or sentiment of each comment.
Silge, J., and Robinson, D. Text Mining with R: A Tidy Approach. https://www.tidytextmining.com/tidytext