Hi everyone,
I'm having trouble with a regex expression which should be fairly easy, I just can't make out the problem.
I have a vector that looks something like this:
vec <- c("TP1.CTRL.2", "X", "TP1.CTRL.4", "X.1", "TP1.CTRL.5" "X.2")
and I want to swap all the "^(X.*)" entries (so all with an X or an X, a dot, and a number) for a new string.
I checked with a regex tester (https://regexr.com/) if the patterns get recognized, everything looks good.
But when I try the following code, it doesn't work:
for(i in 1:length(vec)){
vec[i] <- ifelse(vec[i] == "^(X.*)", 'CPM', vec[i])
}
print(vec)
Nothing gets exchanged for "CPM", no error pops up; this means that r doesnt think the regex expression matches any of the vector entries, even though it should.... what am I missing?
Thanks for your help!