Re: [R] Construct time series objects from raw data stored in csv files

2007-04-16 Thread Jeffrey J. Hallman
As Gabor said, ts series are not good for weekly data.  That's why I created the
tis (Time Indexed Series) class, in the 'fame' package.  You don't need the
Fame database to use them.


-- 
Jeff

__
R-help@stat.math.ethz.ch 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-13 Thread tom soyer
Thanks Gabor!!

On 4/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
  What should I do for weekly and daily data series? Are there functions
  similar to yearmon() for other time intervals? I see that there is a
  built-in yearqtr() function for quarterly data, but that's it.

 ts series cannot directly represent daily and weekly
 series other than somehow deciding on a numeric representation
 for time.

 Here we will use the number of days and the number of weeks
 since the Epoch (1970-01-01) and assume we assume weeks
 start on Sunday.  We will also do it over again using the number
 of weeks since the first point in the series and the number of
 days since the first point.

 Lines.raw is from my original post on this thread.


 z - read.zoo(textConnection(Lines.raw), header = TRUE, sep = ,)

 # ts series will represent days as no of days since Epoch
 zday - z
 frequency(zday) - 1
 tsday - as.ts(zday)

 # ts series will represent weeks as no of weeks since Epoch
 zweek - zday
 offset - -3 # weeks start on Sun
 # offset - -4 # weeks start on Mon
 zweek - aggregate(z, (as.numeric(time(z)) + offset) %/% 7, mean)
 frequency(zweek) - 1
 tsweek - as.ts(zweek)

 ##
 # alternately use number of days since first day in series
 # and number of weeks since first week in series


 zday0 - aggregate(zday, time(zday) - min(time(zday)), c)
 frequency(zday0) - 1
 tsday0 - as.ts(zday0)

 zweek0 - aggregate(zweek, time(zweek) - min(time(zweek)), c)
 frequency(zweek0) - 1
 tsweek0 - as.ts(zweek0)




-- 
Tom

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] 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.


[R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread tom soyer
Hi,

I have time series data stored in csv files (see below for an example of the
data). I understand that in order to analyze my data in R, I need to first
transform it into a ts object. Howeve, I could not find an example on how
exactly to do that. Is ts the only function I need? What are the steps that
I need to go through to build a time series object from raw data like this?

Thanks,

Tom

--- DATE,VALUE
1921-01-01,19.000
1921-02-01,18.400
1921-03-01,18.300
1921-04-01,18.100
1921-05-01,17.700
1921-06-01,17.600
1921-07-01,17.700
1921-08-01,17.700
1921-09-01,17.500
1921-10-01,17.500
1921-11-01,17.400
1921-12-01,17.300
1922-01-01,16.900
1922-02-01,16.900
1922-03-01,16.700
1922-04-01,16.700
1922-05-01,16.700
1922-06-01,16.700
1922-07-01,16.800
1922-08-01,16.600
1922-09-01,16.600
1922-10-01,16.700
1922-11-01,16.800
1922-12-01,16.900

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread Achim Zeileis
On Thu, 12 Apr 2007, tom soyer wrote:

 Hi,

 I have time series data stored in csv files (see below for an example of the
 data). I understand that in order to analyze my data in R, I need to first
 transform it into a ts object. Howeve, I could not find an example on how
 exactly to do that. Is ts the only function I need? What are the steps that
 I need to go through to build a time series object from raw data like this?

With the zoo package you can do
  library(zoo)
  z - read.zoo(yourdata.csv, sep = ,)
  plot(z)

See
  vignette(zoo, package = zoo)
for more information and also some more details about other time series
classes.
Z

 Thanks,

 Tom

 --- DATE,VALUE
 1921-01-01,19.000
 1921-02-01,18.400
 1921-03-01,18.300
 1921-04-01,18.100
 1921-05-01,17.700
 1921-06-01,17.600
 1921-07-01,17.700
 1921-08-01,17.700
 1921-09-01,17.500
 1921-10-01,17.500
 1921-11-01,17.400
 1921-12-01,17.300
 1922-01-01,16.900
 1922-02-01,16.900
 1922-03-01,16.700
 1922-04-01,16.700
 1922-05-01,16.700
 1922-06-01,16.700
 1922-07-01,16.800
 1922-08-01,16.600
 1922-09-01,16.600
 1922-10-01,16.700
 1922-11-01,16.800
 1922-12-01,16.900

   [[alternative HTML version deleted]]

 __
 [EMAIL PROTECTED] 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.



__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread Gabor Grothendieck
On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
 Hi,

 I have time series data stored in csv files (see below for an example of the
 data). I understand that in order to analyze my data in R, I need to first
 transform it into a ts object. Howeve, I could not find an example on how
 exactly to do that. Is ts the only function I need? What are the steps that
 I need to go through to build a time series object from raw data like this?


Try pasting this into an R session:



Lines.raw - DATE,VALUE
1921-01-01,19.000
1921-02-01,18.400
1921-03-01,18.300
1921-04-01,18.100
1921-05-01,17.700
1921-06-01,17.600
1921-07-01,17.700
1921-08-01,17.700
1921-09-01,17.500
1921-10-01,17.500
1921-11-01,17.400
1921-12-01,17.300
1922-01-01,16.900
1922-02-01,16.900
1922-03-01,16.700
1922-04-01,16.700
1922-05-01,16.700
1922-06-01,16.700
1922-07-01,16.800
1922-08-01,16.600
1922-09-01,16.600
1922-10-01,16.700
1922-11-01,16.800
1922-12-01,16.900

library(zoo)
# replace next line with something like this:
#  z - read.zoo(myfile.dat, header = TRUE, sep = ,)
z - read.zoo(textConnection(Lines.raw), header = TRUE, sep = ,)
time(z) - as.yearmon(time(z))
as.ts(z)

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread tom soyer
Thanks Gabor!

I think your example works, but check this out:

 as.ts(z)
  Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
1921 19.0 18.4 18.3 18.1 17.7 17.6 17.7 17.7 17.5 17.5 17.4 17.3
1922 16.9 16.9 16.7 16.7 16.7 16.7 16.8 16.6 16.6 16.7 16.8 16.9
 is.ts(z)
[1] FALSE


How come R does not recognize z as a ts object? It is a ts object, isn't it?

On 4/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
  Hi,
 
  I have time series data stored in csv files (see below for an example of
 the
  data). I understand that in order to analyze my data in R, I need to
 first
  transform it into a ts object. Howeve, I could not find an example on
 how
  exactly to do that. Is ts the only function I need? What are the steps
 that
  I need to go through to build a time series object from raw data like
 this?
 

 Try pasting this into an R session:



 Lines.raw - DATE,VALUE
 1921-01-01,19.000
 1921-02-01,18.400
 1921-03-01,18.300
 1921-04-01,18.100
 1921-05-01,17.700
 1921-06-01,17.600
 1921-07-01,17.700
 1921-08-01,17.700
 1921-09-01,17.500
 1921-10-01,17.500
 1921-11-01,17.400
 1921-12-01,17.300
 1922-01-01,16.900
 1922-02-01,16.900
 1922-03-01,16.700
 1922-04-01,16.700
 1922-05-01,16.700
 1922-06-01,16.700
 1922-07-01,16.800
 1922-08-01,16.600
 1922-09-01,16.600
 1922-10-01,16.700
 1922-11-01,16.800
 1922-12-01,16.900
 
 library(zoo)
 # replace next line with something like this:
 #  z - read.zoo(myfile.dat, header = TRUE, sep = ,)
 z - read.zoo(textConnection(Lines.raw), header = TRUE, sep = ,)
 time(z) - as.yearmon(time(z))
 as.ts(z)




-- 
Tom

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread Gabor Grothendieck
On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
 Thanks Gabor!

 I think your example works, but check this out:

  as.ts(z)
   Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
 1921 19.0 18.4 18.3 18.1 17.7 17.6 17.7 17.7 17.5 17.5 17.4 17.3
 1922 16.9 16.9 16.7 16.7 16.7 16.7 16.8 16.6 16.6 16.7 16.8 16.9
  is.ts(z)
 [1] FALSE

The above outputs as.ts(z) on the console.  If you want to
assign it to a variable you need to do so:

tz - as.ts(z)
is.ts(tz) # TRUE

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread tom soyer
Oh yes, I forgot. Thanks!!

On 4/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
  Thanks Gabor!
 
  I think your example works, but check this out:
 
   as.ts(z)
Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
  1921 19.0 18.4 18.3 18.1 17.7 17.6 17.7 17.7 17.5 17.5 17.4 17.3
  1922 16.9 16.9 16.7 16.7 16.7 16.7 16.8 16.6 16.6 16.7 16.8 16.9
   is.ts(z)
  [1] FALSE

 The above outputs as.ts(z) on the console.  If you want to
 assign it to a variable you need to do so:

 tz - as.ts(z)
 is.ts(tz) # TRUE




-- 
Tom

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread tom soyer
Gabor,

What should I do for weekly and daily data series? Are there functions
similar to yearmon() for other time intervals? I see that there is a
built-in yearqtr() function for quarterly data, but that's it.

Thanks!

On 4/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
  Thanks Gabor!
 
  I think your example works, but check this out:
 
   as.ts(z)
Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
  1921 19.0 18.4 18.3 18.1 17.7 17.6 17.7 17.7 17.5 17.5 17.4 17.3
  1922 16.9 16.9 16.7 16.7 16.7 16.7 16.8 16.6 16.6 16.7 16.8 16.9
   is.ts(z)
  [1] FALSE

 The above outputs as.ts(z) on the console.  If you want to
 assign it to a variable you need to do so:

 tz - as.ts(z)
 is.ts(tz) # TRUE




-- 
Tom

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] 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.


Re: [R] Construct time series objects from raw data stored in csv files

2007-04-12 Thread Gabor Grothendieck
On 4/12/07, tom soyer [EMAIL PROTECTED] wrote:
 What should I do for weekly and daily data series? Are there functions
 similar to yearmon() for other time intervals? I see that there is a
 built-in yearqtr() function for quarterly data, but that's it.

ts series cannot directly represent daily and weekly
series other than somehow deciding on a numeric representation
for time.

Here we will use the number of days and the number of weeks
since the Epoch (1970-01-01) and assume we assume weeks
start on Sunday.  We will also do it over again using the number
of weeks since the first point in the series and the number of
days since the first point.

Lines.raw is from my original post on this thread.


z - read.zoo(textConnection(Lines.raw), header = TRUE, sep = ,)

# ts series will represent days as no of days since Epoch
zday - z
frequency(zday) - 1
tsday - as.ts(zday)

# ts series will represent weeks as no of weeks since Epoch
zweek - zday
offset - -3 # weeks start on Sun
# offset - -4 # weeks start on Mon
zweek - aggregate(z, (as.numeric(time(z)) + offset) %/% 7, mean)
frequency(zweek) - 1
tsweek - as.ts(zweek)

##
# alternately use number of days since first day in series
# and number of weeks since first week in series


zday0 - aggregate(zday, time(zday) - min(time(zday)), c)
frequency(zday0) - 1
tsday0 - as.ts(zday0)

zweek0 - aggregate(zweek, time(zweek) - min(time(zweek)), c)
frequency(zweek0) - 1
tsweek0 - as.ts(zweek0)

__
[EMAIL PROTECTED] 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.