0

Filtering row which contains a certain string using dplyr

Hi guys,

V2 is a column, factor classification.

I am trying to filter the following but I get 0 values:

MSFT <- dplyr::filter(Tweets, grepl("$MSFT", V2) ) 

Strangely, this works:

MSFT <- dplyr::filter(Tweets, grepl("MSFT", V2) ) 

But I want MSFT specifically and not MSFTXXX or MSFT e.t.c

Thanks :)

Community
  • 1
  • 1
Wagish
  • 3
  • 6
  • escape the `$` (i.e. `\\$`) – hrbrmstr Sep 21 '15 at 18:23
  • `$` means "end of string"---so stick it where you want the end to be: `"MSFT$"`. "$MSFT" is looking for a line that ends, and then after the end has "MSFT". – Gregor Thomas Sep 21 '15 at 18:26
  • ah, i thought it was more `$MSFT` like a stock quote. you'll need to add regex word boundaries if you want `MSFT` anywhere in the 140 chars. – hrbrmstr Sep 21 '15 at 18:30
  • Cool Thanks ! @hrbrmstr, yup it is like a hastag in twitter, I'm dealing with twitter data during the crash in 2008-2010. I managed to do the following: $GE' <- dplyr::filter(Tweets, grepl("\\bGE$\\b", V2) ) to get the exact filter :) – Wagish Sep 22 '15 at 15:22
  • http://stackoverflow.com/questions/17906003/detecting-word-boundary-with-regex-in-data-frame-in-r – Wagish Sep 22 '15 at 15:24

0 Answers0