shad
shad

Reputation: 13

grepl function in R

I have a data set and I want to find the rows which include a specific word "result". I used the following function but it seems it doesn't work correctly. Any suggestion?

data$new<-data.frame(grepl("result",col1)) 


data:
col1                            col2
ABC result VDCbvdc home          22
fgc school                       34
university result home exam      45
exam math stat                   65

Upvotes: 0

Views: 67

Answers (1)

Erin
Erin

Reputation: 386

try data$new <- grepl("result",data$col1)

data$new should be assigned to a vector, but you're trying to feed it a data frame. also, col1 only exists inside data, so you'll need data$col1.

Upvotes: 1

Related Questions