[R] don't want xtab sorting "numeric" factors...
Jeff D. Hamann
jeff.hamann at forestinformatics.com
Tue Jun 7 01:54:42 CEST 2005
r-gurus,
I couldn't find an answer to this and after an hour or so of trying all
types or ways to do this, I've given up for now.
I'm having trouble getting the results from xtabs to generate
"unsorted" factors. I've generated a sample data.frame I want to
create a table from, using xtabs, and the results are presented below,
> temp
treatment itpa qmd tht
1 0 100 7.287263 3.362501
2 25 100 10.461070 4.118217
3 50 100 16.671731 5.814391
4 75 100 24.033238 8.264608
5 100 100 27.554497 9.586341
6 0 200 7.032527 3.355118
7 25 200 9.632828 4.039846
8 50 200 14.821584 5.659913
9 75 200 20.470692 7.791525
10 100 200 22.977827 8.901247
11 0 300 6.839360 3.355788
12 25 300 9.437649 4.070102
13 50 300 13.609004 5.545991
14 75 300 18.159601 7.387135
15 100 300 20.194335 8.380818
16 0 600 6.232509 3.330317
17 25 600 8.371084 3.990557
18 50 600 11.512385 5.235263
19 75 600 14.463214 6.605290
20 100 600 16.030137 7.467160
21 0 900 5.938640 3.338342
22 25 900 7.610695 3.891203
23 50 900 10.209530 4.917330
24 75 900 12.528651 6.157436
25 100 900 13.708622 6.791764
26 0 1200 5.841058 3.389716
27 25 1200 7.174748 3.859241
28 50 1200 9.238635 4.689011
29 75 1200 11.424713 5.688340
30 100 1200 12.349254 6.275864
> t <- xtabs( temp$tht ~ temp$itpa + temp$treatment )
t <- xtabs( temp$tht ~ temp$itpa + temp$treatment )
>
> t
temp$treatment
temp$itpa 0 100 25 50 75
100 3.362501 9.586341 4.118217 5.814391 8.264608
1200 3.389716 6.275864 3.859241 4.689011 5.688340
200 3.355118 8.901247 4.039846 5.659913 7.791525
300 3.355788 8.380818 4.070102 5.545991 7.387135
600 3.330317 7.467160 3.990557 5.235263 6.605290
900 3.338342 6.791764 3.891203 4.917330 6.157436
>
the factors represent real values and shouldn't be sorted as
strings. The table should read,
> t
temp$treatment
temp$itpa 0 25 50 75 100
100 3.362501 4.118217 5.814391 8.264608 9.586341
200 3.355118 4.039846 5.659913 7.791525 8.901247
300 3.355788 4.070102 5.545991 7.387135 8.380818
600 3.330317 3.990557 5.235263 6.605290 7.467160
900 3.338342 3.891203 4.917330 6.157436 6.791764
1200 3.389716 3.859241 4.689011 5.688340 6.275864
>
this wouldn't be that big of an issue if I only did this once for the
results, but I'm using this in Sweave and need create the tables after
thousands of iterations.
Any help would be greatly appreciated.
Thanks,
Jeff.
--
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon 97339-1421
phone 541-754-1428
fax 541-752-0288
jeff.hamann at forestinformatics.com
www.forestinformatics.com
More information about the R-help
mailing list