r - How to check in every row in a column if it contains a substring -


let's have column 'name' in dataframe df:

apple apple123 app aple 

and, want check if every row in name column contains word apple. way did use grepl, grepl('apple',df$name), hoping return 'true','true','false','false','false', however, returned 5 'false' instead.

did wrong here, if not grepl, function should use?

i 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 same data.frame

dat <- data.frame(v=c('apple', 'apple123', 'app', 'be', 'aple')) grepl('apple', dat$v) [1]  true  true false false false 

which same if do

with(dat, grepl('apple', v)) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -