Dear list,
I have a vector of strings that cannot be described by one pattern. So
let's say I construct a vector of patterns in the same length as the vector
of strings, can I do the element wise pattern recognition and string
substitution.
For example,
pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
patterns <- c(pattern1,pattern2)
strings <- c('TX.WT.CUT.mean','mg.tx.cv')
Say I want to extract "WT.CUT" from the first string and "tx" from the
second string. If I do
sub(patterns, '\\2', strings), only the first pattern will be used.
looping the patterns doesn't work the way I want. Appreciate any comments.
Thanks.
Jun
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.