[R] Creating variable names

Douglas Bates bates at stat.wisc.edu
Wed Apr 21 00:31:04 CEST 2004

Gene Hammel <genehammel at comcast.net> writes:

> My apologies for asking what is doubtless a dumb question, but I have
> scant experience in R.
> It would be very convenient in doing lots of plots to be able to do
> them in a loop that stepped through a vector of variable names. For
> example one could say
> x<-("mydates")

   You misquoted that line.  There is no function before the (

> y<-c("foo1","foo2","foo3") #where "foon" were vectors
> plot(x,y[1],type="n")
> points(x,y[1])
> points(x,y[2],pch=2)
> points(x,y[3],pch=3)

The general approach in R is often called "whole object".  That is,
you try to put your data into a structure that will facilitate the
operations you wish to perform.  In this case bind the responses into
a matrix and use matplot

matplot(x, cbind(foo1, foo2, foo3), type = 'p')

Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/

More information about the R-help mailing list