Mehdi Farhangian Mehdi Farhangian - 4 months ago 16
R Question

Filter the data contains a particular string

I wish to filter those of my data that contains a particular string. Let's assume this is my data set

#dst

first second
24 Sienna,Zoe,Dylan
32 Amber,John,Noah,Sienna
72 Daniel,Mike,Zoe


And I wish to have only data that contains "Zoe". So, I'd like to have this output

#output

first second
24 Sienna,Zoe,Dylan
72 Daniel,Mike,Zoe

Answer

You can use the grep or grepl factions.
If your data frame is named "dst", then this should work:

output<-dst[grep("Zoe", dst$second),]
Comments