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]]
?paste Please (re-) read the "Introduction to R" document supplied with the software for faster answers. Also, please read the Posting Guide mentioned at the bottom of every message on this list. In particular, providing data in raw tabular form is often ambiguous, and the use of the dput function to prepare data samples for questions will allow readers to more quickly identify difficulties you may be having. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Akhil dua <akhil.dua.12 at gmail.com> wrote:>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.
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.