Hi I have a data frame and i need to change the date format in it. my dataframe X Date 1 1/1/2009 2 2/1/2009 3 3/1/2009 I need to change it to 2009-01-01 -- View this message in context: http://r.789695.n4.nabble.com/changing-date-format-in-a-dataframe-tp4076411p4076411.html Sent from the R help mailing list archive at Nabble.com.
changing date format in a dataframe
4 messages · arunkumar1111, Milan Bouchet-Valat, R. Michael Weylandt +1 more
Le mercredi 16 novembre 2011 ? 06:12 -0800, arunkumar1111 a ?crit :
Hi I have a data frame and i need to change the date format in it. my dataframe X Date 1 1/1/2009 2 2/1/2009 3 3/1/2009 I need to change it to 2009-01-01
See ?as.Date. In your case, I think you should use df[[2]] <- as.Date(df[[2]], format="%d/%m/%Y") This is assuming df is your dataframe, and that you're using the day/month/year syntax. To print it into another format, see ?format.Date Regards
Can you dput() your data frame? There are a different few time objects in R and details might depend which one you have. Though, if it's printing like that, I'd guess it's actually a string that you can convert to a Date using as.Date(, format = XXX) where you can work out the formatting from the documentation in ?strptime. Michael
On Wed, Nov 16, 2011 at 9:12 AM, arunkumar1111 <akpbond007 at gmail.com> wrote:
Hi I have a data frame and i need to change the date format in it. my dataframe X Date 1 1/1/2009 2 2/1/2009 3 3/1/2009 I need to change it to 2009-01-01 -- View this message in context: http://r.789695.n4.nabble.com/changing-date-format-in-a-dataframe-tp4076411p4076411.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.
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20111116/f12f1afa/attachment.pl>