Forgive me if this is very obvious, I tried searching but couldn't find something specific to data frames on grep
.
I was trying to search on two different columns, geo
and text
. I thought that grep
, which returns row numbers, and grepl
, which returns a logical vector, would return the same value for the test term "frank
> length(unique(temp[grepl("frank",temp[which(temp$geo=="New York"),"text"]),"text"]))
[1] 195
> length(unique(temp[grep("frank",temp[which(temp$geo=="New York"),"text"]),"text"]))
[1] 13
I tried filtering by unique
thinking that I was getting duplicate rows, but it looks like this is not the case. I'm inclined to think that grepl
is the correct function to use since grepl
and !grepl
return the complete search space, but I'm not sure. Interestingly returning the entire row gives me a different value for both.
Which one should I be using in order to get the correct results?