Re: [R] simple table/matrix problem

2010-07-31 Thread Xu Wang
Hadley Wickham's reshape package makes tasks like these pretty easy. http://cran.r-project.org/web/packages/reshape/index.html -- View this message in context: http://r.789695.n4.nabble.com/simple-table-matrix-problem-tp2307969p2308713.html Sent from the R help mailing list archive at Nabble.co

Re: [R] simple table/matrix problem

2010-07-30 Thread William Dunlap
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Robin Hankin > Sent: Friday, July 30, 2010 6:40 AM > To: r-help@r-project.org > Subject: [R] s

Re: [R] simple table/matrix problem

2010-07-30 Thread Henrique Dallazuanna
Try this: Reduce(function(...)merge(..., by = 'ind', all = TRUE), lapply(list(x, y, z), stack)) On Fri, Jul 30, 2010 at 10:39 AM, Robin Hankin wrote: > Hi > > Given three vectors > > x <- c(fish=3, dogs=5, bats=2) > y <- c(dogs=1, hogs=3) > z <- c(bats=3, dogs=5) > > How do I create a multi

[R] simple table/matrix problem

2010-07-30 Thread Robin Hankin
Hi Given three vectors x <- c(fish=3, dogs=5, bats=2) y <- c(dogs=1, hogs=3) z <- c(bats=3, dogs=5) How do I create a multi-way table like the following? > out x y z bats 2 0 3 dogs 5 1 5 fish 3 0 0 hogs 0 3 0 ('out' is a matrix). See how the first line shows 'x' has 2 bats, 'y' has