[R Tips] Use “grepl” to search through text data
[한국어안내는 제목을 클릭해주시길 바랍니다]
The project I got myself into requires me to identify brands just by looking at the given store name. I could look through all 3,000,000 store names, but thats silliness talking. CTRL+F is a basic command for searching keywords. “grepl” is the CTRL+F of R.
Lets first begin by creating a text data set
Data set of random alphabet is created
sample <- paste(rep(letters,2), rep(letters, each=2), sep=“”)
x <- letters
x <- x[order(x, decreasing = TRUE)]
sample <- paste(sample, rep(x,2), sep=“”)
sample <- as.data.frame(cbind(sample, 1:length(sample)))
colnames(sample) <- c(“name”, “number”)
sample <- sample[,c(2,1)]
number name
1 1 aaz
2 2 bay
3 3 cbx
4 4 dbw
5 5 ecv
6 6 fcu
7 7 gdt
… (the code above should lead you to a data frame looking like this)