[R] how to replace the second "-"

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 20 05:38:06 CEST 2006


Try this:

sub("(-[^-]*)-", "\\10", c("1-1-1", "1-1-2", "1-2-1"))


On 10/19/06, ronggui <ronggui.huang at gmail.com> wrote:
> I have a string vector like these:
> [1] "1-1-1" "1-1-2" "1-2-1"
>
> And I wanna replace the second "-" with "0", that is, I wanna get the result
> like: [1] "1-101" "1-102" "1-201".
>
> How should I write the Regular Expressions? Thanks!
>
> --
> »ÆÈÙ¹ó
> Department of Sociology
> Fudan University
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
>



More information about the R-help mailing list