Praveen R Karuppannan Praveen R Karuppannan - 4 months ago 16
R Question

grep String in R

I am using GREP to subset data frame into multiple data frame

Test = Other[ grep("Hi", Other$`Summary`),]


the about code works fine. But I want to grep "PING"

PING = Other[ grep("PING", Other$`Summary`),]


the above statement greps all records where every it finds PING.
But I want to grep only if the word starts with PING

Is there a way to do it.

Answer

Try using \\b as suggested along with .*\\b to indicate the end of the word begining in "PING"

Other[grep("\\bPING.*\\b", Other$`Summary`,perl=T),]