Hi Folks! I'm struggling with dates - but enough about my personal life..... I have two daily time series files. In one (x) the date format is Y/m/d and the other (y) is d/m/y. I used read.zoo on both and they read into R with no problem. Then I use: weekdays(as.Date(x$DATE)) and get what I expect - all the days of the week in my data set. When I use: weekdays(as.Date(y$Date)) I get: Error in fromchar(x) : character string is not in a standard unambiguous format I've tried to set the format= in read.zoo to format="%d/%m/%Y" but this doesn't seem to solve the problem. What's going on here? (I'm new to these dates functions, so please be patient - I'll get the hang out of soon!) Best, John [[alternative HTML version deleted]]
Gabor Grothendieck
2006-Jun-23 20:24 UTC
[R] Problems with weekday extraction from zoo objects
Please provide a reproducible example (and read the posting guide at the bottom of each email). On 6/23/06, Kerpel, John <John.Kerpel at infores.com> wrote:> Hi Folks! > > > > I'm struggling with dates - but enough about my personal life..... > > > > I have two daily time series files. In one (x) the date format is Y/m/d > and the other (y) is d/m/y. I used read.zoo on both and they read into > R with no problem. > > > > Then I use: weekdays(as.Date(x$DATE)) and get what I expect - all the > days of the week in my data set. > > > > When I use: weekdays(as.Date(y$Date)) I get: > > > > Error in fromchar(x) : character string is not in a standard unambiguous > format > > > > I've tried to set the format= in read.zoo to format="%d/%m/%Y" but this > doesn't seem to solve the problem. > > > > What's going on here? (I'm new to these dates functions, so please be > patient - I'll get the hang out of soon!) > > > > Best, > > > > John > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Gabor: In my attempts to provide a reproducible example I now run into the following problems:> SP500<-read.zoo("SP500.csv", sep = ",")Error in read.zoo("SP500.csv", sep = ",") : index contains NAs> DGS10<-read.zoo("DGS10.csv",sep=",")Error in read.zoo("DGS10.csv", sep = ",") : index contains NAs> SP500Error: object "SP500" not found> DGS10Error: object "DGS10" not found>First ten records of SP500.csv: Date Open High Low Close Volume Adj. Close* 3-Jan-50 16.66 16.66 16.66 16.66 1260000 16.66 4-Jan-50 16.85 16.85 16.85 16.85 1890000 16.85 5-Jan-50 16.93 16.93 16.93 16.93 2550000 16.93 6-Jan-50 16.98 16.98 16.98 16.98 2010000 16.98 9-Jan-50 17.08 17.08 17.08 17.08 2520000 17.08 10-Jan-50 17.03 17.03 17.03 17.03 2160000 17.03 11-Jan-50 17.09 17.09 17.09 17.09 2630000 17.09 12-Jan-50 16.76 16.76 16.76 16.76 2970000 16.76 13-Jan-50 16.67 16.67 16.67 16.67 3330000 16.67 First ten records of DGS10.csv DATE VALUE 1/2/1962 4.06 1/3/1962 4.03 1/4/1962 3.99 1/5/1962 4.02 1/8/1962 4.03 1/9/1962 4.05 1/10/1962 4.07 1/11/1962 4.08 1/12/1962 4.08 This worked perfectly yesterday; I did get the NA warnings but it read the entire file(s) correctly. John -----Original Message----- From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] Sent: Friday, June 23, 2006 3:24 PM To: Kerpel, John Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Problems with weekday extraction from zoo objects Please provide a reproducible example (and read the posting guide at the bottom of each email). On 6/23/06, Kerpel, John <John.Kerpel at infores.com> wrote:> Hi Folks! > > > > I'm struggling with dates - but enough about my personal life..... > > > > I have two daily time series files. In one (x) the date format isY/m/d> and the other (y) is d/m/y. I used read.zoo on both and they readinto> R with no problem. > > > > Then I use: weekdays(as.Date(x$DATE)) and get what I expect - all the > days of the week in my data set. > > > > When I use: weekdays(as.Date(y$Date)) I get: > > > > Error in fromchar(x) : character string is not in a standardunambiguous> format > > > > I've tried to set the format= in read.zoo to format="%d/%m/%Y" butthis> doesn't seem to solve the problem. > > > > What's going on here? (I'm new to these dates functions, so please be > patient - I'll get the hang out of soon!) > > > > Best, > > > > John > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html>
On Fri, 23 Jun 2006 16:12:27 -0500 Kerpel, John wrote:> > SP500<-read.zoo("SP500.csv", sep = ",") > Error in read.zoo("SP500.csv", sep = ",") : > index contains NAsWell, there are two problems with this: 1. the CSV is not comma-separated (despite its siffix) and 2. the date format should be specified.> First ten records of SP500.csv: > > Date Open High Low Close > Volume Adj. Close*^^^^^^^^^^^ and I changed this name to "Adj.Close" which gives a syntactically valid name in R. Then I successfully employed: SP500 <- read.zoo("SP500.csv", format = "%d-%b-%y", header = TRUE) DGS10 <- read.zoo("DGS10.csv", format = "%m/%d/%Y", header = TRUE) and then weekdays(time(SP500)) weekdays(time(DGS10)) Z