Let's say I have a column 'name' in the dataframe df
:
apple
apple123
app
be
aple
and, I want to check if every row in the name
column contains the word apple
.
The way I did it was to use grepl
, grepl('apple',df$name)
, I was hoping it would return 'TRUE','TRUE','FALSE','FALSE','FALSE'
, however, it returned 5 'FALSE'
instead.
Did I do anything wrong here, if not grep
l, what function should I use?
I get it running fine
dat <- c('apple', 'apple123', 'app', 'be', 'aple')
grepl('apple', dat)
[1] TRUE TRUE FALSE FALSE FALSE
dat[grepl('apple', dat)]
[1] "apple" "apple123"
This is exactly the same with a data.frame
dat <- data.frame(v=c('apple', 'apple123', 'app', 'be', 'aple'))
grepl('apple', dat$v)
[1] TRUE TRUE FALSE FALSE FALSE
which is the same if you do
with(dat, grepl('apple', v))