[R] Odp: Troubles with the format of dates

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Thu, 27 Nov 2008 15:01:29 +0100

Hi

r-help-bounces_at_r-project.org napsal dne 27.11.2008 14:20:17:

> Dear useRs,
>
> I'm struggling again with date-related stuff: I am using R to draw water

> levels at certain measuring
> stations. My data comes as a tab-delimited text file and looks like
this:
>
> DATUM P1 P2
> ...
> 2006-11-16 425.21 423.99
> 2006-12-15 425.12 423.97
> 2007-01-16 425.16 424.06
> ...
>
> (measurements started in July 2004 and still continue on a monthly or
bi-weekly basis)
>
> This is then plotted using this code:
>
> a<-read.table("dummy_data.tab", sep="\t", header=TRUE, na.strings=c(0))
> x<-as.Date(a$DATUM)
>
> plot(x, a$P1, axes=FALSE, xlim=c(as.Date("2004-07-01"),
as.Date("2009-01-01")),
> ylim=c(423,428), col="red", pch=15, type="o", ylab="Kote [m a.s.l.]",
> main="Dummy Plot")
> points(x, a$P2, col="red", pch=17, type="o", lty="dotted")
> axis(2, at=423:428, tck=1, col="gray60")
> axis.Date(1, at=seq(as.Date("2004-07-01"), as.Date("2009-01-01"),
> by="month"), labels=seq(as.Date("2004-07-01"), as.Date("2009-01-01"),
> by="month"), tck=1, col="gray60")
>
> So far, I've been using this type of date format (yyyy-mm-dd) because
that was
> the only way I could
> get the whole thing to work when I started using R. However, living in
> Switzerland, I would prefer
> the dates to read 16.11.2006 i.e. dd.mm.yyyy or 16. Nov. 2006
(preferably
> using German names for
> the months, if possible).
>
> I've used the chron package to convert my dates to day mon year (16 Nov
2006,
> with or without
> spaces), i.e. I replaced the second line of code with:
>
> x<-format(chron(as.character(a$DATUM), format="y-m-d", out.format="day
mon year"))

Although I am not an expert in time/date functions it seems to me that you just want your labels to be in your preferred format. If it is the case

labels = format(seq(as.Date("2004-07-01"), as.Date("2009-01-01"), by="month"), "%d.%m.%Y")

in your call to axisDate can help you to achieve it.

Regards
Petr

>
> but then I can't plot them any more, because as.Date() no longer is the
> correct function and R gives
> me an error saying there is an invalid xlim-value. Can someone please
point me
> in the right
> direction?
>
> I could easily change the input data to be in dd.mm.yyyy format, if that
helps.
>
> Thanks for your help,
>
> Kathi
>
>
> --
> DropNet AG - Das Unternehmen fuer Ihren Internet-Auftritt!
>
> ______________________________________________
> 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.



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. Received on Thu 27 Nov 2008 - 14:05:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Nov 2008 - 17:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive