[R] lattice and crosstabs with empty cells
Jacob A. Wegelin
wegelin at stat.washington.edu
Thu Jul 11 09:14:40 CEST 2002
Suppose you have a dataframe with two factors, but not all the factor
levels appear together. For instance:
stuff<- structure(list(fac1 = structure(c(2, 1, 2, 2), .Label = c("down",
"up"), class = "factor"), fac2 = structure(c(1, 2, 1, 2), .Label = c("left",
"right"), class = "factor"), x = c(1, 1, 2, 2), y = c(1, 2, 2,
1)), .Names = c("fac1", "fac2", "x", "y"), row.names = c("1",
"2", "3", "4"), class = "data.frame")
> stuff
fac1 fac2 x y
1 up left 1 1
2 down right 1 2
3 up left 2 2
4 up right 2 1
You'd like to make a trellis (lattice) plot conditioned on both
factors. (Thus you expect that one of the panels will have no points
in it.) This attempt fails, however:
> library("lattice")
> xyplot( y ~ x | fac1 * fac2, data=stuff)
Error in pretty(x, ...) : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning messages:
1: no finite arguments to min; returning Inf
2: no finite arguments to max; returning -Inf
3: no finite arguments to min; returning Inf
4: no finite arguments to max; returning -Inf
This does not fail in S-PLUS Version 3.4 Release 1 for DEC alpha,
Digital UNIX (OSF/1) V3.2 : 1996.
A similar problem:
Is there an equivalent to S-PLUS crosstabs(), or SAS PROC FREQ, in
R, that will not fail if there are empty cells? The S-PLUS
crosstabs(), copied into R, fails when one attempts to apply it to
data with empty cells:
> crosstabs( ~ fac1 + fac2, data=stuff)
Error in crosstabs(~fac1 + fac2, data = stuff) :
Object "NULL" not found
The same command does not fail in S-PLUS.
Thanks for any info. The R behavior occurred both in Windows
and in unix. In both cases the R version was dated 2002/04/29.
Jacob A. Wegelin, Ph.D.
University of Washington
Department of Statistics
B-313 Padelford
Box 354322
Seattle WA 98195
http://www.stat.washington.edu/wegelin/
wegelin at stat.washington.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list