knavero
2012-Mar-22 12:24 UTC
[R] read.zoo - combining two columns with date and time respectively into one index column?
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? -- 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.
knavero
2012-Mar-22 12:40 UTC
[R] read.zoo - combining two columns with date and time respectively into one index column?
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. -- 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-tp4495326p4495345.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2012-Mar-22 14:02 UTC
[R] read.zoo - combining two columns with date and time respectively into one index column?
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: > > 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
David Winsemius
2012-Mar-22 14:16 UTC
[R] read.zoo - combining two columns with date and time respectively into one index column?
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. > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
knavero
2012-Mar-22 20:21 UTC
[R] read.zoo - combining two columns with date and time respectively into one index column?
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. -- 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-tp4495326p4496743.html Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- question about user written function (newb question)
- Wrong output due to what I think might be a data type issue (zoo read in problem)
- convert zoo object to "standard" R object so I can plot and output to csv file
- Noob question - Identity argument within aggregate function?
- Convert a column of numbers to a column of strings