[R] simple table/matrix problem

Robin Hankin rksh1 at cam.ac.uk
Fri Jul 30 15:39:52 CEST 2010


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



More information about the R-help mailing list