read.zoo - combining two columns with date and time respectively into one index column?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

read.zoo - combining two columns with date and time respectively into one index column?

knavero
I have three columns in my raw data: date, time, and dry bulb temperature:

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?
Reply | Threaded
Open this post in threaded view
|

Re: read.zoo - combining two columns with date and time respectively into one index column?

knavero
I actually just found an alternative solution which involves setting Excel's or Libre Office Calc's fixed width option then saving it again as a .txt or .csv. If there's a cleaner way of doing this within the R shell, I'm open to ideas.
Reply | Threaded
Open this post in threaded view
|

Re: read.zoo - combining two columns with date and time respectively into one index column?

Gabor Grothendieck
In reply to this post by knavero
On Thu, Mar 22, 2012 at 8:24 AM, knavero <[hidden email]> 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

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: read.zoo - combining two columns with date and time respectively into one index column?

David Winsemius
In reply to this post by knavero

On Mar 22, 2012, at 8:24 AM, knavero 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?

I'm reasonably optimistic that read.zoo will do that. It's capable of  
two column datetime reads. My memory is that you just give the column  
numbers to the index.column argument. You will also need to give a  
format argument since your formats to not look to be bog standard.

>
> --
> View this message in context: http://r.789695.n4.nabble.com/read-zoo-combining-two-columns-with-date-and-time-respectively-into-one-index-column-tp4495326p4495326.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: read.zoo - combining two columns with date and time respectively into one index column?

knavero
In reply to this post by Gabor Grothendieck
Ah yes, sorry about that Gabor. Found a pretty good example in ?read.zoo where it has index = 1:3 and takes in times objects. I must have overlooked it out of impatience. Thanks for the quick and simple feedback however.