Using grep and grepl in R to Find Words in a List
📖 Scenario: Imagine you have a list of fruit names and you want to find which fruits contain the word "apple".
🎯 Goal: You will learn how to use grep and grepl functions in R to search for words inside a list of strings.
📋 What You'll Learn
Create a character vector with fruit names
Create a search word variable
Use
grep to find positions of fruits containing the search wordUse
grepl to get a logical vector showing which fruits contain the search wordPrint the results
💡 Why This Matters
🌍 Real World
Searching text data for specific words or patterns is common in data analysis, such as finding keywords in customer feedback or filtering product names.
💼 Career
Knowing how to use <code>grep</code> and <code>grepl</code> helps in data cleaning, text mining, and preparing data for reports or machine learning.
Progress0 / 4 steps