[R] cbind question, please

Erin Hodgess erinm.hodgess at gmail.com
Fri Apr 24 02:51:18 CEST 2015


Here is the big picture.  I have a character vector with all of the names
of the variables in it.

I want to "cbind" all of the variables to create a matrix.

Doing 3 is straightforward, but many, not so much.

Hence my question.

Thanks so much for your answers!

Sincerely,
Erin


On Thu, Apr 23, 2015 at 7:44 PM, John Kane <jrkrideau at inbox.com> wrote:

> What are you expecting?
>
> dog <- 1:3
> cat <- 2:4
> tree <- 5:7
> big.char <- c("dog","cat","tree")
>
> xx <-  cbind(dog, cat, tree, big.char)
>
> gives me
> xx1  <-  structure(c("1", "2", "3", "2", "3", "4", "5", "6", "7", "dog",
> "cat", "tree"), .Dim = 3:4, .Dimnames = list(NULL, c("dog", "cat",
> "tree", "big.char")))
>
>
>
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: erinm.hodgess at gmail.com
> > Sent: Thu, 23 Apr 2015 18:41:05 -0400
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] cbind question, please
> >
> > Hello!
> >
> > I have a cbind type question, please:  Suppose I have the following:
> >
> > dog <- 1:3
> > cat <- 2:4
> > tree <- 5:7
> >
> > and a character vector
> > big.char <- c("dog","cat","tree")
> >
> > I want to end up with a matrix that is a "cbind" of dog, cat, and tree.
> > This is a toy example.  There will be a bunch of variables.
> >
> > I experimented with "do.call", but all I got was
> > 1
> > 2
> > 3
> >
> > Any suggestions would be much appreciated.  I still think that do.call
> > might be the key, but I'm not sure.
> >
> > R Version 3-1.3, Windows 7.
> >
> > Thanks,
> > Erin
> >
> >
> > --
> > Erin Hodgess
> > Associate Professor
> > Department of Mathematical and Statistics
> > University of Houston - Downtown
> > mailto: erinm.hodgess at gmail.com
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> ____________________________________________________________
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
> Check it out at http://www.inbox.com/marineaquarium
>
>
>


-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com

	[[alternative HTML version deleted]]



More information about the R-help mailing list