[R] read.zoo - combining two columns with date and time respectively into one index column?
ggrothendieck at gmail.com
Thu Mar 22 15:02:44 CET 2012
On Thu, Mar 22, 2012 at 8:24 AM, knavero <knavero at gmail.com> wrote:
> I have three columns in my raw data: date, time, and dry bulb temperature:
> The date format is %Y%m%d and the time format is %H:%M. Any ideas on how to
> read it in such that it looks at the first two columns and then merges it
> into one column combining both the date and time?
index= in read.zoo can be a vector.
URL <- "http://r.789695.n4.nabble.com/file/n4495326/weathDataSDCoron.txt"
toChron <- function(d, t) as.chron(paste(d, t), format = "%Y%m%d %H:%M")
tail1 <- function(x) tail(x, 1) # for duplicate times take last
z <- read.zoo(URL, index = 1:2, FUN = toChron,
header = TRUE, sep = "\t", aggregate = tail1)
See ?read.zoo and the zoo-read vignette for many examples.
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help