[R] element wise pattern recognition and string substitution

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Mon Sep 5 06:30:43 CEST 2016

Your opening assertion is false. 

Provide a reproducible example and someone will demonstrate. 
Sent from my phone. Please excuse my brevity.

On September 4, 2016 9:06:59 PM PDT, Jun Shen <jun.shen.ut at gmail.com> wrote:
>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
>of strings, can I do the element wise pattern recognition and string
>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
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list