Skip to content
Back to formatted view

Raw Message

Message-ID: <CAP01uRmhHaVRmeGrmJ=yoJW5m1zDnEBn7OK4BqWFc0HEcORRDg@mail.gmail.com>
Date: 2012-10-04T11:41:14Z
From: Gabor Grothendieck
Subject: Class for time series
In-Reply-To: <CAP+bYWAEH=MV+TaUXgVNiQx1+pdD_DhJz+Y0=+2Kb8mnV4LNFg@mail.gmail.com>

On Thu, Oct 4, 2012 at 3:07 AM, Hasan Diwan <hasan.diwan at gmail.com> wrote:
> Mr. Emmanuel,
>
> On 4 October 2012 02:43, Poizot Emmanuel <emmanuel.poizot at cnam.fr> wrote:
>
>> Dear all,
>>
>> I have a time serie dataset such as the following with data acquired every
>> 15 minutes:
>>
>> Date    Heure Profondeur Temp?rature Salinit? Turbidit? Chloration
>> 1 2012-07-06 08:47:22     -0.144      22.469    0.011 0.000          0
>> 2 2012-07-06 09:02:21     -0.147      22.476    0.011 0.000          0
>> 3 2012-07-06 09:17:21     -0.139      22.498    0.011 19.323          0
>> 4 2012-07-06 09:32:21     -0.136      22.540    0.011 19.343          0
>> 5 2012-07-06 09:47:21     -0.141      22.510    0.011 19.321          0
>> 6 2012-07-06 10:02:21     -0.139      22.372    0.011 19.280          0
>>
>> I wonder what is the best class to use to manage such time series
>
>
> Use xts whenever dealing with timeseries, to construct:
> xts(data.in[,-1:2], order.by=as.POSIXct(paste(data.in[,1:2])))
>

If you are using xts and reading in the data from an external file
then note that xts loads the zoo package and read.zoo can be used to
do the actually reading:

Lines <- "Date    Heure Profondeur Temp?rature Salinit? Turbidit? Chloration
1 2012-07-06 08:47:22     -0.144      22.469    0.011 0.000          0
2 2012-07-06 09:02:21     -0.147      22.476    0.011 0.000          0
3 2012-07-06 09:17:21     -0.139      22.498    0.011 19.323          0
4 2012-07-06 09:32:21     -0.136      22.540    0.011 19.343          0
5 2012-07-06 09:47:21     -0.141      22.510    0.011 19.321          0
6 2012-07-06 10:02:21     -0.139      22.372    0.011 19.280          0"

library(xts) # also pulls in zoo

# z <- read.zoo("myfile.dat", header = TRUE, index = 1:2, tz = "")
z <- read.zoo(text = Lines, header = TRUE, index = 1:2, tz = "")

x <- as.xts(z)

Here index = 1:2 says that the date/time index is in the first two
columns and tz = "" says to interpret it as POSIXct with the indicated
time zone.  tz = "GMT" is another possibility.

For more info on read.zoo see ?read.zoo .  Also there is a document
entirely devoted to read.zoo examples obtained by issuing:
vignette("zoo-read") .

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com