Re: [R] vectorized sub, gsub, grep, etc.

2015-08-03 Thread Adam Erickson
Interesting. I know of no practical use for such a function. If the first position were 'abb,' sub() would return 'aBb,' failing to replace the second 'b.' I find it hard to believe that's the desired functionality. Writing a looped regex function in Rcpp makes the most sense for speed. Using Boost

Re: [R] vectorized sub, gsub, grep, etc.

2015-08-01 Thread Adam Erickson
> b cda > "aB" "CD" "ef" > > By talking instead about simple string matching, I'm afraid you've rather > hijacked the thread. > > -John > > > -John > > > Adam wrote > > > > > > I

Re: [R] vectorized sub, gsub, grep, etc.

2015-07-31 Thread Adam Erickson
ate this type of operation. Cheers, Adam > On Jul 30, 2015, at 21:09, John Thaden wrote: > > > Can you show what is its solution for the original sample data? Why that > discrepancy for you original sub2() function? > > From:"Adam Erickson" > Date:Thu, Jul

Re: [R] vectorized sub, gsub, grep, etc.

2015-07-30 Thread Adam Erickson
uot; system.time(for(i in 1:5) subCPP(patt, repl, X)) user system elapsed 0.160.000.16 Cheers, Adam On Wednesday, July 29, 2015 at 2:42:23 PM UTC-7, Adam Erickson wrote: > > Further refining the vectorized (within a loop) exact string match > function, I get times b

Re: [R] vectorized sub, gsub, grep, etc.

2015-07-29 Thread Adam Erickson
t; "CD" "" > > > > Granted, whatever it does, it does it faster > > #Old method 1 > > system.time(for(i in 1:5) > > mapply(function(p,r,x) sub(p,r,x, fixed = TRUE),p=patt,r=repl,x=X)) > >user system elapsed > >2.53

Re: [R] vectorized sub, gsub, grep, etc.

2015-07-28 Thread Adam Erickson
"CD" ""* > > Granted, whatever it does, it does it faster > > #Old method 1 > system.time(for(i in 1:5) > mapply(function(p,r,x) sub(p,r,x, fixed = TRUE),p=patt,r=repl,x=X)) > > *user system elapsed2.530.002.52 * > > #Old method 2 &

Re: [R] vectorized sub, gsub, grep, etc.

2015-07-27 Thread Adam Erickson
I know this is an old thread, but I wrote a simple FOR loop with vectorized pattern replacement that is much faster than either of those (it can also accept outputs differing in length from the patterns): sub2 <- function(pattern, replacement, x) { len <- length(x) y <- charac