[R] changing date format in a dataframe

2011-11-16 Thread arunkumar1111
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@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.


Re: [R] changing date format in a dataframe

2011-11-16 Thread R. Michael Weylandt
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, arunkumar akpbond...@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@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.


__
R-help@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.


Re: [R] changing date format in a dataframe

2011-11-16 Thread Mohamed Lajnef
Hi,

If the dates are the same format and the same length you can try this :

dates-c(1/1/2009,2/1/2009,3/1/2009)

dates_new-as.Date(paste(substr(dates,1,3),substr(dates,7,8),sep=/),format=%d/%m/%y),
 
you can change the format to %m/%d/%y

Regards
M


Le 16/11/11 15:12, arunkumar 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


 --
 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@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.



-- 

Mohamed Lajnef,IE INSERM U955 eq 15#
P?le de Psychiatrie#
H?pital CHENEVIER  #
40, rue Mesly  #
94010 CRETEIL Cedex FRANCE #
mohamed.laj...@inserm.fr   #
tel : 01 49 81 32 79   #
Sec : 01 49 81 32 90   #
fax : 01 49 81 30 99   #




[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] changing date format in a dataframe

2011-11-16 Thread Milan Bouchet-Valat
Le mercredi 16 novembre 2011 à 06:12 -0800, arunkumar 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

__
R-help@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.