[R] Date
arun
smartpink111 at yahoo.com
Wed Jul 4 06:41:04 CEST 2012
Hi,
Try this:
Year<-c("01/2000","02/2000","03/2000")
#If you want to convert it directly to month/year
library(zoo)
as.yearmon(Year,format="%m/%Y")
[1] "Jan 2000" "Feb 2000" "Mar 2000"
#As your intention is to have DD/MM/YYYY format,
Year1<-paste("01/",Year,sep="")
Year1
[1] "01/01/2000" "01/02/2000" "01/03/2000"
Year<-as.Date(Year1, format="%m/%d/%Y")
Year
[1] "2000-01-01" "2000-01-02" "2000-01-03"
dat1<-data.frame(Year1,Stock_Prices=1:3)
> dat1
Year1 Stock_Prices
1 01/01/2000 1
2 01/02/2000 2
3 01/03/2000 3
dat2<-data.frame(Year,Stock_Prices=1:3)
> dat2
Year Stock_Prices
1 2000-01-01 1
2 2000-01-02 2
3 2000-01-03 3
A.K.
----- Original Message -----
From: Akhil dua <akhil.dua.12 at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, July 4, 2012 12:13 AM
Subject: [R] Date
Hi
I have monthly data and the dates are in MM/YY Format
I need to convert them into DD/MM/YY format by pasting 01 in place of DD to
all the observations in my Year Column
ex:
Year Stock Prices
01/2000 1
02/2000 2
03/2000 3
I need to convert them to
Year Stock Prices
01/01/2000 1
01/02/2000 2
01/03/2000 3
[[alternative HTML version deleted]]
______________________________________________
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