Reputation: 123
i would like to load the following data structure as a time series into R:
Date 06:00 07:00 .... 22:00
01.11.2011 1 4 .... 42
02.11.2011 6 2 .... 21
...
is this loadable with R ? Do i need to transform my data ? can anybody help me with this?
Upvotes: 1
Views: 780
Reputation: 269586
First create some data:
Lines <- "Date 06:00 07:00 08:00
01.11.2011 1 4 42
02.11.2011 6 2 21"
DF <- read.table(text = Lines, header = TRUE, check.names = FALSE)
Now create zoo object z
using chron
date/times:
library(zoo)
library(chron)
tt <- as.chron(outer(DF[[1]], names(DF)[-1], paste), format = "%d.%m.%Y %H:%M")
z <- zoo(c(as.matrix(DF[-1])), tt)
(Replacing as.chron
with as.POSIXct
would give POSIXct date/times.)
Upvotes: 2