[R] binding vectors or matrix using their names
Liaw, Andy
andy_liaw at merck.com
Wed Mar 24 21:52:05 CET 2004
Perhaps simler:
> x1 <- 1:5
> x2 <- 2:7
> xname <- c("x1", "x2")
> sapply(xname, get)
x1 x2
[1,] 1 2
[2,] 2 3
[3,] 3 4
[4,] 4 5
[5,] 5 6
HTH,
Andy
> From: Stephane DRAY
>
> Hi Tom,
>
> Your approach did not work,
>
> > do.call("cbind", as.list(my.names))
> [,1] [,2]
> [1,] "x" "x2"
>
> but it helps me a lot to find the good one:
>
> do.call("cbind", as.list(parse(text=my.names)))
>
> Thanks,
>
>
> At 14:56 24/03/2004, Tom Blackwell wrote:
>
> >I believe the syntax is
> >
> >result <- do.call(cbind, as.list(my.names))
> >
> >Haven't checked this on your example, though.
> >
> >- tom blackwell - u michigan medical school - ann arbor -
> >
> >On Wed, 24 Mar 2004, Stephane DRAY wrote:
> >
> > > Hello list,
> > > I have two vectors x and x2:
> > >
> > > x=runif(10)
> > > x2=runif(10)
> > >
> > > and one vectors with their names :
> > >
> > > my.names=c("x","x2")
> > >
> > > I would like to cbind these two vectors using their names
> contained in the
> > > vector my.names.
> > > I can create a string with comma
> > > ncomma=paste(my.names,collapse=",")
> > >
> > > and now, I just need a function to transform this string
> into a adequate
> > > argument for cbind:
> > >
> > > cbind(afunction(ncomma))
> > >
> > > Is there in R a function that can do the job ? If not,
> how can I do it ??
> > >
> > > Thanks in advance,
> > > Sincerely.
> > >
> > >
> > > Stéphane DRAY
> > >
> >
> --------------------------------------------------------------
> ------------------------------------
> > >
> > > Département des Sciences Biologiques
> > > Université de Montréal, C.P. 6128, succursale centre-ville
> > > Montréal, Québec H3C 3J7, Canada
> > >
> > > Tel : 514 343 6111 poste 1233
> > > E-mail : stephane.dray at umontreal.ca
> > >
> >
> --------------------------------------------------------------
> ------------------------------------
> > >
> > >
> > Web
> http://www.steph280.freesurf.fr/
> > >
> > >
> ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> > >
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> Stéphane DRAY
>
> --------------------------------------------------------------
> ------------------------------------
>
> Département des Sciences Biologiques
> Université de Montréal, C.P. 6128, succursale centre-ville
> Montréal, Québec H3C 3J7, Canada
>
> Tel : 514 343 6111 poste 1233
> E-mail : stephane.dray at umontreal.ca
> --------------------------------------------------------------
> ------------------------------------
>
> Web
> http://www.steph280.freesurf.fr/
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.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