[R] xyplot and for loops

About this list Date view Thread view Subject view Author view Attachment view

From: Dave Atkins (datkins@u.washington.edu)
Date: Wed 05 May 2004 - 08:40:34 EST


Message-id: <40981BE2.1080607@u.washington.edu>


I'm attempting to use xyplot() within a for() loop to plot the relationship
between a DV and a series of predictor variables, split by 2 conditioning
variables. However, xyplot() does not "seem" to be recognized within the for()
loop; I don't receive any error message, but nothing is plotted and a plotting
device is not opened. When I use the generic function plot(), everything works
as expected. I'm using R v1.9.0 and lattice v0.9-11.

Here's a trivial example:

### create single outcome and two predictors
> y.tmp <- rnorm(20) ; x1.tmp <- rnorm(20) ; x2.tmp <- rnorm(20)
### combine into data.frame
> tmp.df <- data.frame(y.tmp, x1.tmp, x2.tmp)
> tmp.df
         y.tmp x1.tmp x2.tmp
1 1.5022759 -0.150326662 -1.36627981
[snip]
20 1.2667825 -0.070356651 -0.38433160

### simple loop calling the columns of tmp.df to specify x variables
> for (i in 2:3){
+ plot(tmp.df$y.tmp ~ tmp.df[,i])
+ }
### works fine for plot()

### try the same with xyplot()
> for (i in 2:3){
+ xyplot(tmp.df$y.tmp ~ tmp.df[,i])
+ }
### nothing happens; no error msg; no plotting device opened

> xyplot(tmp.df$y.tmp ~ tmp.df[,2])
### without loop works fine and plots relationship of x1.tmp and y.tmp

Can someone see what I'm missing? Any directions/pointers appreciated.

cheers, Dave
datkins@u.washington.edu

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST