Re: [R] Modify string-regular expression

From: Hans-Joerg Bibiko <bibiko_at_eva.mpg.de>
Date: Fri, 30 May 2008 14:03:31 +0200

On 30 May 2008, at 11:25, Romain wrote:
> ...
>
> SCAN <- scan("File.txt",sep="\n", what="raw",blank.lines.skip=F)
> For (i in 1:Nb_param)
> {
> sub('Param[i] = Value_i-1','Param[i] = Value_i-2', SCAN)
> }
>
> ...
>
> I Know how to modify a string with sub when it is a fixed string :
> sub("(K =)([0-9]*)",paste("\\1", Value[i,2]),SCAN)
> But i would like to know if it is possible to use the function paste
> or something else in the first argument of the function sub.
> For example, the correct syntax of :
> ' sub("(Param[i])([0-9]*)",paste("\\1", Value[i,2]),SCAN) '

Have a look at ?gsub

Cheers,

--Hans



R-help_at_r-project.org mailing list
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. Received on Mon 02 Jun 2008 - 04:19:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 04:30:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive