[R] how to referee a dimension name via a variable?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Aug 29 21:59:18 CEST 2011


On 29/08/2011 3:52 PM, Jie TANG wrote:
> thank you , it works .
>
> another problem is if can could define a variable to express the data.frame?
> for example :
> datanam<-c("newdata","newdata2")
> plot(datanam[1][[newnam[1]]])

Use get():

plot(get(datanam[1])[[newnam[1]]]))

Duncan Murdoch

>
> 2011/8/30 Justin Haynes<jtor14 at gmail.com>
>
> >  try:
> >
> >  newnam<-paste('newdatadat',dayno,sep='')
> >
> >  plot(test[[newnam[1]]])
> >
> >
> >  On Mon, Aug 29, 2011 at 12:29 PM, Jie TANG<totangjie at gmail.com>  wrote:
> >
> >>  hi, R-users
> >>    I have a data.frame for example  test$newdataday24 and test$newdataday48
> >>  I can plot them by
> >>  plot(test$newdataday24)
> >>  but now i want to plot different data by define a variable to describe
> >>  them
> >>  dayno<-c(24,48)
> >>  newnam<-paste("test$newdataday",dayno,sep="")
> >>  plot(newnam[1])
> >>
> >>  but i failed,the error message said that something wrong with plot.window
> >>
> >>  what can i do to fix my script ? thanks
> >>  -
> >>  TANG Jie
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >>  ______________________________________________
> >>  R-help at r-project.org mailing list
> >>  https://stat.ethz.ch/mailman/listinfo/r-help
> >>  PLEASE do read the posting guide
> >>  http://www.R-project.org/posting-guide.html
> >>  and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >
>
>



More information about the R-help mailing list