Re: [R] Wild card characters

From: Dhiren DSouza <dhiren22_at_hotmail.com>
Date: Sun 31 Jul 2005 - 06:42:30 EST


Thank you both :)

-Dhiren

From: Gabor Grothendieck <ggrothendieck@gmail.com> Reply-To: Gabor Grothendieck <ggrothendieck@gmail.com> To: Uwe Ligges <ligges@statistik.uni-dortmund.de> CC: Dhiren DSouza <dhiren22@hotmail.com>, r-help@stat.math.ethz.ch Subject: Re: [R] Wild card characters
Date: Sat, 30 Jul 2005 16:31:37 -0400

Another way to do it is:

sub("[.].*", ".41", x)

This says to replace the first dot and everything after by .41. When . appears
in a character class, i.e. [.], then you don't need backslashes. Also you don't need backslashes in the second argument.

On 7/30/05, Uwe Ligges <ligges@statistik.uni-dortmund.de> wrote:
> Dhiren DSouza wrote:
>
> > I have a string '982323.1' and would like to replace everything after
the
> > '.' with a '41'. So the string should look like '982323.41'. The code
I
> > use to do this is
> >
> > sub('\.$','41',982323.1)
>
> You have to escape "\", see ?regexp:
>
> sub('\\.[[:digit:]]*$','\\.41', "982323.1")
>
> Uwe Ligges
>
>
>
> > This works fine as long as there is only 1 digit after the decimal. If
I
> > have '982323.10', then the result of the code is '982323.141' instead
of
> > '982323.41'
> >
> > How do I fix the code to replace all characters after the decimal by
41?
> >
> > Thank you
> >
> > -D
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!

http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jul 31 06:47:57 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 14:59:53 EST