[R] grep
Brian Smith
b@mith030465 @ending from gm@il@com
Mon Jul 16 19:46:20 CEST 2018
Hi,
I was trying to find a pattern ("ABHD14A") in a character string ('xgen' in
example below) using grepl. Note that the individual members may be
separated by a semi-colon.
The correct answer should return:
"ABHD-ACY1 ; ABHD14A" "ABHD14A ; YYY"
I have tried three approaches, but still seem a bit off. Attempt 2 below
gets closest, but it also returns a hit where my pattern is a substring.
Here is my code:
===========
xgen <- c("XYZ","ABHD-ACY1 ; ABHD14A","ABHD14AXX","ABHD14A ; YYY")
ga <- "ABHD14A"
# 1.
kx <- grepl(paste0("^",ga,"$"),xgen)
xgen[kx]
# 2.
ky <- grepl(ga,xgen)
xgen[ky]
==============
What do I need to add/change in #2 above?
many thanks!
[[alternative HTML version deleted]]
More information about the R-help
mailing list