[R] Why does this work?
apjaworski@mmm.com
apjaworski at mmm.com
Mon May 20 21:18:39 CEST 2002
I waxs just checking examples in lattice levelplot and I ran into this
strange (?) behavior I do not understand.
Here is the example:
x <- seq(pi/4, 5*pi, length = 100)
y <- seq(pi/4, 5*pi, length = 100)
r <- sqrt(outer(x^2, y^2, "+"))
grid <- expand.grid(x=x, y=y)
At this point grid is a 10000*2 data frame and r is a 100*100 matrix. Now
comes a surprising part.
grid$z <- cos(r^2) * exp(-r/(pi^3))
This does not generate any error. But typing
grid
produces
Error in data.frame(x = c(" 0.7853982", " 0.9361311", " 1.0868641", "
1.2375971", :
arguments imply differing number of rows: 10000, 100
Moreover
dim(grid)
[1] 10000 3
but
grid[1:5, ]
produces an output with 102 columns named x, y, z.1, ..., z.100
and
grid[101, ]
produces "subscript out of bound" error.
Finally
levelplot(z~x*y, grid, cuts = 50, xlab="", ylab="", main="Weird
Function", colorkey = FALSE)
generates a proper contour plot. Could somebody explain to me why this
actually works? Thanks in advance,
Andy
PS. This happens using precompiled R-1.5.0 (recently patched version
posted by Prof. Ripley) on a Win2000 machine.
__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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