0

i want to search columns 2 and 3 for the word "is" which should return 1, 2, and 3. what code should i use? thanks in advance.

c1  c2                  c3    
1   a dog is barking    I am late
2   it is raining       I will run
3   we are eating       this is fun
4   I am sleepy         maybe tomorrow
5   later tonight       we all laugh

grepl("is", "file.csv", ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) 

to no avail. thanks!

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Neil
  • 3
  • 3
  • 2
    Welcome to SO! What code did you try that didn't work or what resources did you research that did not turn up that _kinda_ solved the problem but didn't fully solve it? SO is (generally) not a code-writing service and I suspect this is well-traveled territory on SO. Perhaps a supplementary question is: what would you use to find substrings in a plain character vector? If you can't answer that, then you likely should do a bit more research. – hrbrmstr Oct 15 '18 at 01:39
  • grepl("is", "file.csv", ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) – Neil Oct 15 '18 at 01:55
  • but did not work – Neil Oct 15 '18 at 01:55
  • that belongs in the question and also suggests you may want to invest some more time in some basic R tutorials. – hrbrmstr Oct 15 '18 at 01:58

1 Answers1

1

You can use paste to make columns c2 and c3 into a single list of strings and then test for the presence of "is" using grep

grep("\\bis\\b", paste(df$c2, df$c3))
G5W
  • 36,531
  • 10
  • 47
  • 80