Re: [R] * within quote

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 15 May 2007 10:13:09 -0400

On 5/15/07, elyakhlifi mustapha <elyakhlifi_mustapha_at_yahoo.fr> wrote:
> hello,
>
> I have an argument of a the list a like this
>
> > a[[18]]
> [1] "C744=(C627*C177)/100"
>
>
> and I wanna seperate the character and the mathematics symbol to use it like a formula
> and why when I used the strsplit function i obtain as follow
>
> > strsplit(a[[18]], '\\W')
> [[1]]
> [1] "C744" "" "C627" "C177" "" "100"
>
> and as follow
>
> > strsplit(a[[18]], '\\w')
> [[1]]
> [1] "" "" "" "" "=(" "" "" "" "*" "" "" "" ")/" "" ""
>
> I don't understand why the star "*" doesn't create space between "C627" and "C177"
>

You can see what is going on by doing this:

> txt <- " C744=(C627*C177)/100"
> gsub("(\\w)", "[\\1]", txt)

[1] " [C][7][4][4]=([C][6][2][7]*[C][1][7][7])/[1][0][0]"
> gsub("(\\W)", "[\\1]", txt)

[1] "[ ]C744[=][(]C627[*]C177[)][/]100"

The portions within [...] are the separators and everything else is output as content separated by those separators.



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. Received on Tue 15 May 2007 - 14:50:04 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 Tue 15 May 2007 - 15:02:02 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.