-1

I have a data table in R that has names numbers and emails

  1. john smith 131234123412 email address
  2. sally smith 2314423423 email address

They are separated by column

I want to be able to search for every instances where "john" is mentioned and then return the whole row.

Michael
  • 19
  • 3

2 Answers2

1

It's really helpful for people wanting to help you to have a reproducible example - here's a link to explain how to do this easily: How to make a great R reproducible example

Without a reproducible example, it's a bit difficult to be exact with an answer, but here's something to nudge you in the right direction:

df[grepl("john", df$first_name), ]

I've named the data table df here and the column containing the name "john" as first_name.

'grepl' will search the first_name column for the word john. The data frame will then be filtered to contain any row where "john" is present.

Jay Achar
  • 1,156
  • 9
  • 16
0

Another option is str_detect with filter

library(stringr)
library(dplyr)
df %>%
    filter(str_detect(first_name, 'john'))
akrun
  • 874,273
  • 37
  • 540
  • 662