Praveen R Karuppannan Praveen R Karuppannan - 1 year ago 119
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 Source

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),]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download