[R] Date formats

arun smartpink111 at yahoo.com
Wed Jun 20 03:23:40 CEST 2012


Hi,

Since you need the monthly averages, I thought it might be helpful to have the month and the year alone in the plot when compared to the whole date.


Try this:
str2<-c("01OCT1928","01NOV1928","01DEC1928","01JAN1929")
x1<-as.Date(str2,format="%d%b%Y")
library(zoo)as.yearmon(x1)

[1] "Oct 1928" "Nov 1928" "Dec 1928" "Jan 1929"

A.K.






----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: "walt at dataanalyticscorp.com" <walt at dataanalyticscorp.com>
Cc: R help <r-help at r-project.org>
Sent: Tuesday, June 19, 2012 7:04 PM
Subject: Re: [R] Date formats

Hi,

Try this:
 str1<-c("01OCT1928","02OCT1928","03OCT1928","04OCT1928")
strptime(str1,"%d%b%Y")
[1] "1928-10-01" "1928-10-02" "1928-10-03" "1928-10-04"

#or you can use this:


 x<-as.Date(str1,format="%d%b%Y")
 x
[1] "1928-10-01" "1928-10-02" "1928-10-03" "1928-10-04"



A.K.




----- Original Message -----
From: Data Analytics Corp. <walt at dataanalyticscorp.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, June 19, 2012 8:00 AM
Subject: [R] Date formats

Hi,

I imported an excel table (using read.csv) of Dow Jones monthly average closings where the first variable is a date as a character string such as "01OCT1928".  How do I convert this to a date variable so I can plot monthly average closings against date using ggplot2?

Thanks,

Walt

________________________

Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
walt at dataanalyticscorp.com
www.dataanalyticscorp.com

______________________________________________
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.



More information about the R-help mailing list