Text Mining with Bag-of-Words in R
Clean and count text in R with the bag-of-words method, build word clouds and dendrograms, then analyze employee reviews in a case study.
Text mining with the bag-of-words method turns unstructured text into word counts that can be measured and compared, setting aside the order in which the words appear. Working in R, you prepare a corpus with the tm and qdap packages, build term-document and document-term matrices, and read the results through word clouds and dendrograms. Employee reviews of Amazon and Google then serve as the text for an HR analytics question.
What You Will Achieve
- Turn raw text from a vector or data frame into a clean corpus and count how often each term appears.
- Design word clouds and word networks that show what two sets of documents share and what sets them apart.
- Cluster related terms into a dendrogram and look past single words with bigrams and adjusted frequency weights.
- Plan and run a text mining project on employee reviews, ending with HR analytics insights.
Program Overview
Bag-of-Words Basics and Text Preprocessing
Starts with what text mining is and how raw text becomes a corpus that is ready for counting.
- Building a VCorpus from a vector or a data frame
- Cleaning functions in tm and qdap
- Stop words, word stemming and stem completion
- Term-document and document-term matrices
Word Clouds, Word Networks and Clustering
Turns frequent terms into visuals, then extends the bag of words with clustering, associations and multi-word tokens.
- Frequent terms, word cloud colors and prebuilt palettes
- Common and dissimilar words, polarized tag clouds and word networks
- Distance matrices, dendrograms and word association
- N-gram tokenization, frequency weights and metadata in tm
HR Analytics Case Study on Amazon and Google Reviews
Applies the full workflow to employee reviews of two tech companies, following the steps of an organized text mining project.
- Problem definition and identifying the text sources
- Text organization, feature extraction and analysis of pros and cons
- Comparing positive and negative reviews
- Reaching conclusions and recommendations
Certificate Awarded (Paid)
Job Outlook
Bag-of-words text mining in R is used wherever large amounts of unstructured text need to be summarized and compared, such as employee reviews studied for HR analytics.
Good for: R users who want a code-based workflow for cleaning, counting and visualizing text, and who like finishing with a complete worked case.
Keep in mind: Bag-of-words counts words and sets their order aside, with n-grams as the main way past single words; the exercises run on the tm and qdap packages.
Bottom line: A tm and qdap based course that closes by setting Amazon and Google employee reviews against each other.
Frequently Asked Questions
What is the bag-of-words method?
It represents a piece of text by how often each word appears and sets aside the order the words come in. That count is the basis for every matrix, word cloud and cluster built in the course.
Which R packages do the exercises use?
The text work centers on the tm and qdap packages, used for cleaning text, removing stop words, stemming and finding frequent terms. The tm package also builds the term matrices and stores document metadata.
What data does the case study analyze?
The final chapter works with employee reviews of Amazon and Google, split into pros and cons. You organize the text, extract features, compare positive and negative reviews of the two companies, and draw conclusions for an HR analytics question.
How do n-grams change the analysis?
Tokenizing text into n-grams lets the matrices count word pairs such as bigrams instead of single words only. One lesson looks at how bigrams change the word clouds built from the same text.
Please log in to report a problem with this page.


There are no reviews yet.