Created
December 3, 2014 12:43
-
-
Save AndrewLJackson/0aefdfab9f6cfa4d8248 to your computer and use it in GitHub Desktop.
How to convert month-year data to POSIX date format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # some data specifying the month and year | |
| month <- c( "Sep-10", | |
| "Oct-10", | |
| "Nov-10", | |
| "Jan-11") | |
| # It would appear that strptime and related | |
| # as.POSIXct functions require there to be a | |
| # day specified. Here I prepend the month-year | |
| # data with the first day. | |
| dd <- paste( 1, month, sep="" ) | |
| # then use strptime to convert to a full POSIX | |
| # date format. | |
| # %d reads in the da | |
| # %b- reads in the abbreviated month followed by "-" | |
| # %y reads in the year without century. | |
| # NB it uses the current locale to add the timezone | |
| # and in this case seems to be taking account of d | |
| # daylight savings time by differentiating between | |
| # BST and GMT | |
| mm <- strptime(dd, format = "%d%b-%y") | |
| print(mm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment