[R] changing date format in a dataframe

Milan Bouchet-Valat nalimilan at club.fr
Wed Nov 16 15:41:13 CET 2011


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



More information about the R-help mailing list