passing a string to expand.grid

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

passing a string to expand.grid

Thomas Roth (geb. Kaliwe)
Hi R-Users,

I'm having a problem with strings.

My string looks like this "c(-1,1), c(-1,1)" and I would like to pass it
to expand.grid so that expand.grid(c(-1,1),c(-1,1)) will be done.

Cheers,

Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: passing a string to expand.grid

Gabor Grothendieck
Try this:

x <- "c(-1,1), c(-1,1)"
eval(parse(text = paste("expand.grid(", x, ")")))

On 5/12/06, Thomas Kaliwe <[hidden email]> wrote:

> Hi R-Users,
>
> I'm having a problem with strings.
>
> My string looks like this "c(-1,1), c(-1,1)" and I would like to pass it
> to expand.grid so that expand.grid(c(-1,1),c(-1,1)) will be done.
>
> Cheers,
>
> Thomas
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: passing a string to expand.grid

Thomas Roth (geb. Kaliwe)
Thank you

-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Freitag, 12. Mai 2006 16:26
An: Thomas Kaliwe
Cc: [hidden email]
Betreff: Re: [R] passing a string to expand.grid

Try this:

x <- "c(-1,1), c(-1,1)"
eval(parse(text = paste("expand.grid(", x, ")")))

On 5/12/06, Thomas Kaliwe <[hidden email]> wrote:
> Hi R-Users,
>
> I'm having a problem with strings.
>
> My string looks like this "c(-1,1), c(-1,1)" and I would like to pass
it

> to expand.grid so that expand.grid(c(-1,1),c(-1,1)) will be done.
>
> Cheers,
>
> Thomas
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html