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 <rk...@cam.ac.uk> 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-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 zero bats, and 'z' has
> 3 bats
> and so on for each line.
> The real application would have a matrix of size ~10 by ~10000.
>
>
>
>
> --
> Robin K. S. Hankin
> Uncertainty Analyst
> University of Cambridge
> 19 Silver Street
> Cambridge CB3 9EP
> 01223-764877
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to