Hi,
I tried to attach these files before as .csv and they did not go through.. This time they are .txt files.. I am trying to get the attached following two timeseries (these are small subsets of the whole thing) into R so I can merge them using zoo.
tmp <- read.table("baltimore.csv", sep = " ") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = "%y %m %d"))
tmp1 <- read.table("baltimorefludata.csv", sep = " ") ##This is timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = "%m %d %y"))
R is not recognizing Date or YEARMODA as dates..Any suggestions on what I am doing wrong or how to fix it would be greatly appreciated!!!
Sincerely,
tom
Thomas Heiman, PhD
Info Systems Eng, Sr
The MITRE Corporation | Center for Enterprise Modernization
Office: 703-983-2951 | theiman at mitre.org<mailto:theiman at mitre.org>
______________________________________________
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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: timeseries1sample.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110523/0f5b73ba/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: timeseries2.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110523/0f5b73ba/attachment-0001.txt>
getting time series into r
5 messages · Heiman, Thomas J., Ben Bolker, David Winsemius +1 more
Heiman, Thomas J. <theiman <at> mitre.org> writes:
tmp <- read.table("baltimore.csv", sep = " ") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = "%y %m %d"))
tmp1 <- read.table("baltimorefludata.csv", sep = " ") ##This is timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = "%m %d %y"))
I think you need format="%m/%d/%Y"
On May 23, 2011, at 4:31 PM, Ben Bolker wrote:
Heiman, Thomas J. <theiman <at> mitre.org> writes:
tmp <- read.table("baltimore.csv", sep = " ") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = ))
In this file you have no separators in the dates so the format would be "%Y%m%d". It's also not a csv file .... no commas
tmp1 <- read.table("baltimorefludata.csv", sep = " ") ##This is
timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = ))
For this one the format would be "%m/%d/%Y". There also appeared to be no whitespace after some of the entries, so you might need utils::read.fwf()
I think you need format="%m/%d/%Y"
______________________________________________ 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
On May 23, 2011, at 5:16 PM, David Winsemius wrote:
On May 23, 2011, at 4:31 PM, Ben Bolker wrote:
Heiman, Thomas J. <theiman <at> mitre.org> writes:
tmp <- read.table("baltimore.csv", sep = " ") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = ))
In this file you have no separators in the dates so the format would be "%Y%m%d". It's also not a csv file .... no commas
tmp1 <- read.table("baltimorefludata.csv", sep = " ") ##This is
timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = ))
For this one the format would be "%m/%d/%Y". There also appeared to be no whitespace after some of the entries, so you might need utils::read.fwf()
OH. They were tabs. And there was a header line... so
> tmp1
V1
1 Date\tCount
2 9/28/2003\t1505
3 10/5/2003\t1535
Try instead:
> tmp1 <- read.table("~/Downloads/timeseries1sample.txt", sep = "\t",
header =TRUE) ##This is timeseries 1
> tmp1$Date <- as.Date(as.character(tmp1$Date), format="%m/%d/%Y")
> tmp1
Date Count
1 2003-09-28 1505
2 2003-10-05 1535
3 2003-10-12 1549
4 2003-10-19 1466
Then use zoo.
I think you need format="%m/%d/%Y"
David Winsemius, MD West Hartford, CT
On Mon, May 23, 2011 at 4:05 PM, Heiman, Thomas J. <theiman at mitre.org> wrote:
Hi,
I tried to attach these files before as .csv and they did not go through.. This time they are .txt files.. ?I am trying to get the attached following two timeseries (these are small subsets of the whole thing) into R so I can merge them using zoo.
tmp <- read.table("baltimore.csv", sep = " ") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = "%y %m %d"))
tmp1 <- read.table("baltimorefludata.csv", sep = " ") ##This is timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = "%m %d %y"))
R is not recognizing Date or YEARMODA as dates..Any suggestions on what I am doing wrong or how to fix it would be greatly appreciated!!!
Try these. Note that in the second series the number of fields does
not match the number in the header so we just skip the header:
library(zoo)
z1 <- read.zoo("timeseries1sample.txt", format = "%m/%d/%Y", header = TRUE)
z2 <- read.zoo("timeseries2.txt", format = "%Y%m%d", skip = 1)
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com