[R] converting dataframe into multiple time series

jwd jwd at surewest.net
Mon Aug 25 03:53:52 CEST 2014

On Sun, 24 Aug 2014 09:52:35 +0900
Bill <william108 at gmail.com> wrote:

> Hello. Can someone suggest how to do this:
> for (i in 2:length(colnames(allvar.df))) {
> var=colnames(allvar.df)[i]
> timeSeriesName = paste(var,".time.series")
> varRef=paste(var,".df$",var)
> varDate=paste(var,".df$date")
> timeSeriesName <- ts(varRef,
> start = c(year(min(varDate)),month(min(varDate))),
> end = c(year(max(varDate)),month(max(varDate))),
> frequency=12)
> }
First, you should probably do some reading.  For starters look at
Modern Applied Statics with S by Venables and Ripley, possibly
Adler's R In a Nutshel and Maindonald and Brown's Data Analysis and
Graphics Using R, and definitely Shumway and Stoffer's Time Series
Analysis and Its Applications: With Examples in R.  READ the sections
on time series. You also want to look into - minimally - xts and zoo.
Depending on the nature of your data - examples are really necessary -
either xts or zoo may be what you want.  Or, you could simply export
each variable in your data.frame to a separate time series.  


More information about the R-help mailing list