[R] How to best divide table by table
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Sat Oct 28 09:58:21 CEST 2006
Serguei Kaniovski <kaniovsk at wsr.ac.at> writes:
> For example,
>
> year X1958 X1973 X1981 X1986 X1995 X2004 X2007
> 1 QMT 12 41 45 54 62 232 255
> 2 Belgium 2 5 5 5 5 12 12
> 3 France 4 10 10 10 10 29 29
>
> year X1958 X1973 X1981 X1986 X1995 X2004 X2007
> 1 QMT 12 41 45 54 62 232 255
> 2 Belgium 9054483 9741700 9859000 9859000 10137000 10418000 10497000
> 3 France 45800391 53294898 55419102 56898199 59418699 62177398 63209000
>
> mat1/mat2 produces
>
> year X1958 X1973 X1981 X1986 X1995 X2004 X2007
> 1 NA 1.00e+00 1.00e+00 1.00e+00 1.00e+00 1.00e+00 1.00e+00 1.00e+00
> 2 NA 2.21e-07 5.13e-07 5.07e-07 5.07e-07 4.93e-07 1.15e-06 1.14e-06
> 3 NA 8.73e-08 1.88e-07 1.80e-07 1.76e-07 1.68e-07 4.66e-07 4.59e-07
>
> with NA in the first column. Serguei
So these are _not_ tables, but dataframes and you're trying to take
the ratio of two character vectors. So don't do that. Instead,
tbl1 <- as.table(mat1[-1])
rownames(tbl1) <- mat1[1,]
etc.
Or just put column 1 back in if you insist on sticking with data
frames. Or cbind(mat[1,],mat1[-1]/mat2[-1]).
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list