0
0
R Programmingprogramming~15 mins

Why text processing is common in R Programming - See It in Action

Choose your learning style9 modes available
Why Text Processing is Common
📖 Scenario: Imagine you work at a company that collects customer feedback through online reviews. These reviews are written in plain text. To understand what customers like or dislike, you need to process this text data.
🎯 Goal: You will create a simple R program that stores some customer reviews, sets a keyword to search for, counts how many reviews contain that keyword, and then prints the count. This shows why text processing is common: to find useful information in written data.
📋 What You'll Learn
Create a vector called reviews with exactly these three strings: "Great product, fast delivery", "Poor packaging, but good quality", "Excellent customer service"
Create a variable called keyword and set it to the string "good"
Use a for loop with the variable review to go through each element in reviews
Inside the loop, check if keyword is found in review using grepl()
Create a variable called count to keep track of how many reviews contain the keyword
Print the final value of count
💡 Why This Matters
🌍 Real World
Companies often collect customer feedback, social media posts, or product reviews as text. Processing this text helps find common opinions or problems quickly.
💼 Career
Text processing skills are useful for jobs in data analysis, marketing, customer support, and anywhere understanding written feedback or documents is important.
Progress0 / 4 steps
1
Create the reviews vector
Create a vector called reviews with exactly these three strings: "Great product, fast delivery", "Poor packaging, but good quality", and "Excellent customer service"
R Programming
Need a hint?

Use the c() function to create a vector with the three exact strings.

2
Set the keyword variable
Create a variable called keyword and set it to the string "good"
R Programming
Need a hint?

Assign the string "good" to the variable keyword.

3
Count reviews containing the keyword
Create a variable called count and set it to 0. Then use a for loop with the variable review to go through each element in reviews. Inside the loop, use grepl(keyword, review) to check if keyword is in review. If yes, add 1 to count.
R Programming
Need a hint?

Start count at 0. Use a for loop to check each review. Use grepl() to find the keyword.

4
Print the count
Write a print() statement to display the value of count
R Programming
Need a hint?

Use print(count) to show how many reviews contain the keyword.