Skip to content
Prev 306930 / 398506 Next

Class for time series

On Thu, Oct 4, 2012 at 3:07 AM, Hasan Diwan <hasan.diwan at gmail.com> wrote:
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") .