|
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 [hidden email] www.dataanalyticscorp.com ______________________________________________ [hidden email] 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. |
|
On Jun 19, 2012, at 8:00 AM, Data Analytics Corp. wrote: > 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? ?strptime # has the format specs that you can use with ... ?as.Date -- David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] 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. |
|
In reply to this post by Data Analytics Corp.-2
Hi Walt,
as.Date("01OCT1928", "%d%b%Y") works for me. See also ?strftime Regards, Jon On Tue, Jun 19, 2012 at 8:00 PM, Data Analytics Corp. <[hidden email]> wrote: > 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 > [hidden email] > www.dataanalyticscorp.com > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. |
|
In reply to this post by Data Analytics Corp.-2
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. <[hidden email]> To: [hidden email] 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 [hidden email] www.dataanalyticscorp.com ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
|
In reply to this post by Data Analytics Corp.-2
Hello,
Try as.Date("01OCT1928", format="%d%b%Y") [1] "1928-10-01" Note that though probably not a problem to you, this is locale specific. In Portugal, the string corresponding to the same date would be "01OUT1928". The variable to set using Sys.setlocale() would be LC_TIME. For date formats the help page you want is help("strptime") ?strptime Hope this helps, Rui Barradas Em 19-06-2012 13:00, Data Analytics Corp. escreveu: > 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 > [hidden email] > www.dataanalyticscorp.com > > ______________________________________________ > [hidden email] 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. ______________________________________________ [hidden email] 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. |
|
In reply to this post by arun kirshna
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 <[hidden email]> To: "[hidden email]" <[hidden email]> Cc: R help <[hidden email]> 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. <[hidden email]> To: [hidden email] 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 [hidden email] www.dataanalyticscorp.com ______________________________________________ [hidden email] 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. ______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
