Importing data into “zoo” objects

The following makes use of the zoo package. You may need to install it from CRAN using the code install.packages("zoo") if you want to run this on your computer. (The package is already installed on the notebook container, however.)

library(zoo)
Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

The data file “unemployment.csv” used below consists of data originally downloaded from the OECD Database website.

unemployment_z <- read.csv.zoo("unemployment.csv")
str(unemployment_z)
'zoo' series from 1970 to 1999
  Data: num [1:30, 1:29] 0.557 0.689 0.912 1 2.132 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:29] "Germany" "France" "Italy" "Netherlands" ...
  Index:  int [1:30] 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 ...
Text <- "2012/1/6 20
2012/1/7 30
2012/1/8 40
"
read.zoo(text=Text)
2012-01-06 2012-01-07 2012-01-08 
        20         30         40 
read.zoo(text=Text,format="%Y/%m/%d")
2012-01-06 2012-01-07 2012-01-08 
        20         30         40 
Text <- "date,time,x,y
2011-05-08,22:45:21,4,41
2011-05-08,22:45:22,5,42
2011-05-08,22:45:23,5,42
2011-05-08,22:45:24,6,43
"
zobj <- read.csv.zoo(text=Text,
                     index.column=1:2)
zobj
                    x  y
2011-05-08 22:45:21 4 41
2011-05-08 22:45:22 5 42
2011-05-08 22:45:23 5 42
2011-05-08 22:45:24 6 43