[R] use grep in lists and vectors
arun
smartpink111 at yahoo.com
Mon Jan 13 03:43:27 CET 2014
Hi,
May be this helps:
mapply(grep,'^Ab$',test.list)
#or
lapply(test.list,function(x) grep("^Ab$",x))
A.K.
On Sunday, January 12, 2014 9:31 PM, Hermann Norpois <hnorpois at gmail.com> wrote:
Hello,
I want to detect Ab not Abc. For a normal vector
test
[1] "A" "Ab" "GG" "GA" "H" "Abc" "Gz" "HU"
> grep ("^Ab$", test)
[1] 2
works well.
For
test.list
[[1]]
[1] "A" "Ab" "GG" "GA"
[[2]]
[1] "H" "Abc" "Gz" "HU"
grep ("^Ab$", test.list)
integer(0)
doest not work.
Why?
How do I detect exclusively Ab in a list context?
Thanks hermann
> dput (test.list)
list(c("A", "Ab", "GG", "GA"), c("H", "Abc", "Gz", "HU"))
> dput (test)
c("A", "Ab", "GG", "GA", "H", "Abc", "Gz", "HU")
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list