[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

data set names, variable names, simplification



Recall that lm accepts an argument data=whatever so it knows where to find your variables.

plot does not accept a data= argument, so we have been boring ourselves to death typing in mydataframe$x and such.

The "with" command in R can solve this hassle.  Run this code to see:

mydf <- data.frame(ind=1:100)
mydf$x <- rnorm(100)
mydf$y <- rnorm(100)
plot(x,y)
# previous fails, saying: Error in plot(x, y) : object "x" not found
# we have been fixing that by going plot(mydf$x,mydf$y)
# instead try
with(mydf, plot(x,y))
# previous succeeds, makes picture as desired.

--
Paul E. Johnson                       email: pauljohn_AT_ku.edu
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700