[R] passing a string to expand.grid

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 12 16:25:57 CEST 2006


Try this:

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

On 5/12/06, Thomas Kaliwe <hamstersquats at web.de> 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
>
> ______________________________________________
> 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
>




More information about the R-help mailing list