On Thu, Mar 22, 2012 at 8:24 AM, knavero <knav...@gmail.com> wrote:
> I have three columns in my raw data: date, time, and dry bulb temperature:
>
> http://r.789695.n4.nabble.com/file/n4495326/weathDataSDCoron.txt
> weathDataSDCoron.txt
>
> 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.

library(zoo)
library(chron)

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.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to