I have a dataframe that looks like this: head(x) Period AP Al MA BB All 1 200812 903,231 1,985,460 905,422 3,312,088 7,106,201 2 200901 880,491 1,924,111 892,980 3,006,050 6,703,631 3 200902 883,994 1,926,169 890,021 3,247,530 6,947,714 4 200903 888,021 1,901,182 892,593 3,216,730 6,898,526 5 200904 869,024 1,829,841 857,723 3,121,458 6,678,046 6 200905 847,450 1,776,100 847,593 3,110,783 6,581,925 x$Period is a numeric value that represents the year and month. How would I take those values and turn them into dates so that I could plot the various columns vs the date ? -- View this message in context: http://r.789695.n4.nabble.com/Creating-dates-to-plot-tp4649677.html Sent from the R help mailing list archive at Nabble.com.
Creating dates to plot
4 messages · eric, PtitBleu, PIKAL Petr +1 more
Hello Eric,
strptime("201206",format="%Y%m") gives NA (I don't know why but I'm a
newbie).
The only solution I found is to add "01" as a day to have a complete date
(Year Month Day):
x$Period<-as.Date(paste(x$Period,"01",sep=""),format="%Y%m%d")
Then you get a Date format you can use to plot graph.
I think you will get better solutions from advanced users.
Have a good day,
Ptit Bleu.
--
View this message in context: http://r.789695.n4.nabble.com/Creating-dates-to-plot-tp4649695p4649704.html
Sent from the R help mailing list archive at Nabble.com.
Hi x$dat <- as.Date(paste(x$Period,0,1, sep=""), format="%Y%m%d") shall do it. Petr
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of eric Sent: Friday, November 16, 2012 12:46 AM To: r-help at r-project.org Subject: [R] Creating dates to plot I have a dataframe that looks like this: head(x) Period AP Al MA BB All 1 200812 903,231 1,985,460 905,422 3,312,088 7,106,201 2 200901 880,491 1,924,111 892,980 3,006,050 6,703,631 3 200902 883,994 1,926,169 890,021 3,247,530 6,947,714 4 200903 888,021 1,901,182 892,593 3,216,730 6,898,526 5 200904 869,024 1,829,841 857,723 3,121,458 6,678,046 6 200905 847,450 1,776,100 847,593 3,110,783 6,581,925 x$Period is a numeric value that represents the year and month. How would I take those values and turn them into dates so that I could plot the various columns vs the date ? -- View this message in context: http://r.789695.n4.nabble.com/Creating- dates-to-plot-tp4649677.html Sent from the R help mailing list archive at Nabble.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.
HI,
How about this?
library(zoo)
?Period<-c("201206","201207","201208")
?as.yearmon(Period,format="%Y%m")
#[1] "Jun 2012" "Jul 2012" "Aug 2012"
A.K.
----- Original Message -----
From: PtitBleu <ptit_bleu at yahoo.fr>
To: r-help at r-project.org
Cc:
Sent: Friday, November 16, 2012 2:56 AM
Subject: Re: [R] Creating dates to plot
Hello Eric,
strptime("201206",format="%Y%m") gives NA (I don't know why but I'm a
newbie).
The only solution I found is to add "01" as a day to have a complete date
(Year Month Day):
x$Period<-as.Date(paste(x$Period,"01",sep=""),format="%Y%m%d")
Then you get a Date format you can use to plot graph.
I think you will get better solutions from advanced users.
Have a good day,
Ptit Bleu.
--
View this message in context: http://r.789695.n4.nabble.com/Creating-dates-to-plot-tp4649695p4649704.html
Sent from the R help mailing list archive at Nabble.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.