ok..thanks
- Original Message -
From: Don MacQueen macque...@llnl.gov
To: raje...@cse.iitm.ac.in, r-help r-help@r-project.org
Sent: Fri, 01 Oct 2010 20:51:06 +0530 (IST)
Subject: Re: [R] Converting a dataframe column from string to datetime
Youâre working too hard. Use this:
tms
Hi,
I have a dataframe column of the form
v-c(Fri Feb 05 20:00:01.43000 2010,Fri Feb 05 20:00:02.274000 2010,Fri
Feb 05 20:00:02.274000 2010,Fri Feb 05 20:00:06.34000 2010)
I need to convert this to datetime form. I did the following..
lapply(v,function(x){strptime(x, %a %b %d %H:%M:%OS %Y)})
Is it okay with you?
Reduce(rbind, lapply(lapply(v,function(x){strptime(x, %a %b %d %H:%M:%OS
%Y)}), as.character))
--
View this message in context:
http://r.789695.n4.nabble.com/Converting-a-dataframe-column-from-string-to-datetime-tp2853709p2869793.html
Sent from the R help mailing list
I think you want to use as.POSIXct to get the date value:
v-c(Fri Feb 05 20:00:01.43000 2010,Fri Feb 05 20:00:02.274000 2010,Fri
Feb 05 20:00:02.274000 2010,Fri Feb 05 20:00:06.34000 2010)
x - as.POSIXct(v, format= %a %b %d %H:%M:%OS %Y)
x
[1] 2010-02-05 20:00:01 EST 2010-02-05 20:00:02 EST
Youre working too hard. Use this:
tms - as.POSIXct(strptime(v, %a %b %d %H:%M:%OS %Y))
Take note of the fact that there are two types of datetime objects: POSIXct
and POSIXlt.
Your unlist() gave what seemed a strange result because you used on an lt
object. Had you given it a ct
5 matches
Mail list logo