YSK the date format YYYY-MM-DD is the international standard. It's a great format to use anywhere you put dates. It's especially useful when including dates in file names. This will allow all files to sort by date when sorting alphabetically.
Date format only month and year? - Google Docs Editors Community
r - Converting year and month ("yyyy-mm" format) to a date? - Stack Overflow
Date Format.
Videos
Why YSK: YYYY-MM-DD is the International (ISO) Standard format for dates. This format makes the most sense for reasons of sorting and also eliminates any confusion due to different date formatting in different regions. This is especially useful when you have files in a folder that have dates in the name.
Since dates correspond to a numeric value and a starting date, you indeed need the day. If you really need your data to be in Date format, you can just fix the day to the first of each month manually by pasting it to the date:
month <- "2009-03"
as.Date(paste(month, "-01", sep=""))
Try this. (Here we use text=Lines to keep the example self contained but in reality we would replace it with the file name.)
Lines <- "2009-01 12
2009-02 310
2009-03 2379
2009-04 234
2009-05 14
2009-08 1
2009-09 34
2009-10 2386"
library(zoo)
z <- read.zoo(text = Lines, FUN = as.yearmon)
plot(z)
The X axis is not so pretty with this data but if you have more data in reality it might be ok or you can use the code for a fancy X axis shown in the examples section of ?plot.zoo .
The zoo series, z, that is created above has a "yearmon" time index and looks like this:
> z
Jan 2009 Feb 2009 Mar 2009 Apr 2009 May 2009 Aug 2009 Sep 2009 Oct 2009
12 310 2379 234 14 1 34 2386
"yearmon" can be used alone as well:
> as.yearmon("2000-03")
[1] "Mar 2000"
Note:
"yearmon"class objects sort in calendar order.This will plot the monthly points at equally spaced intervals which is likely what is wanted; however, if it were desired to plot the points at unequally spaced intervals spaced in proportion to the number of days in each month then convert the index of
zto"Date"class:time(z) <- as.Date(time(z)).
I understand the "Official" date format in Canada is YYYY-MM-DD.
Question: In casual or day to day settings, or small office / home business etc, is that what you actually use? Or do you use the more common DD/MM/YY, or do you this the USA MM/DD/YY style?
What is the "norm" for Canadians? Do you write Day first or Month first?