r - regex variable substitution in "replacement" argument -


I have a string in R. I want to find the part of the string and add a variable number of zero. For example, I have 1 2 3 . Sometimes I want to be it 1 203 ; Sometimes I want it to be 1 2000 3 . If I store the number of the enclosed ones in a variable, then how can I use it in the "Replacement" part of the sub command?

I have a mind code like this:

  s < - '1 2 3' z & lt; - '3' sub ('(\\ s \\ d) (\\ s. *)', '\\ 10 {Z} \\ 2', s)   

Code returns 1 20 {z} 3 . But should I get the code like this?

One way

  s <- '1 2 3' z   

But this is a little clunky.

Try operator associated with package:

  required (string ) "abc"% stri +% "123abc" ## [1] "abc123abc"    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -