Even at the risk of being this question labeled as duplicated, I am going to ask since all the related questions I have checked do not solve my problem...
I have a labs vector and I want to find the elements that are exact matches to 3 groups stored in a groups variable.
set.seed(1) labs <- sample(c(rep('BC-89HX',3), rep('BC-89HX with 2% Puricare + 5% Merquat',3), rep('Own SH',4)), 10) labs groups <- c('BC-89HX','BC-89HX with 2% Puricare + 5% Merquat','Own SH') I want to identify the "BC-89HX" group elements (not the "BC-89HX with 2% Puricare + 5% Merquat" ones)
grep(groups[1], labs, val=TRUE, fixed=TRUE) #finds more elements than the ones I need grep(paste(groups[1],"$",sep=""), labs, val=TRUE, fixed=TRUE) #does not work grep(paste("\\b",groups[1],"\\b",sep=""), labs, val=TRUE, fixed=TRUE) #does not work Any help?
does not workis not clear. In the first case of 'grep', I get 6 matches out of the 10 elements in 'labs'. What is your expected output?grep(paste0("^", groups[1], "$"), labs, val=TRUE)# [1] "BC-89HX" "BC-89HX" "BC-89HX"In that case you can use==as welllabs[labs == groups[1]]paste0! I was tryinggrep(paste(groups[1], "$"), labels(dend.obj), val=TRUE, fixed=TRUE)causegroups[1]contains-