Grepl function not working in R

1.6k views Asked by At

I am trying to grep for multiple strings in the data frame

head(data1) 

colname.x 

Facebook
POF Free Dating App
WhatsApp Messenger
WhatsApp Messenger
Facebook
Facebook
Facebook
Facebook
WhatsApp Messenger
POF Free Dating App
Facebook
Facebook
WhatsApp Messenger
Facebook
Messenger
Facebook
Facebook
Dropbox
WhatsApp Messenger
Facebook
Dropbox
WhatsApp Messenger
WhatsApp Messenger
Facebook

I am appending the data frame to include new social media column

data1$socialmedia <- as.numeric(grepl("messenger | facebook | whatsapp " , data1$colname.x ))  

However all I get is 0 i.e FALSE instead of True/1 where Facebook/Whatsapp etc is present, I am not sure why this is the case.

1

There are 1 answers

1
pachadotdev On BEST ANSWER

R is space, uppercase, encoding sensitive!

try data1$socialmedia <- as.numeric(grepl("Messenger|Facebook|WhatsApp",data1$colname.x ))

if you explain your idea better I can provide a better answer :)