An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101001/9be92a45/attachment.pl>
Converting a dataframe column from string to datetime
5 messages · rajeshj at cse.iitm.ac.in, Arun Kumar Saha, jim holtman +1 more
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 archive at Nabble.com.
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" [3] "2010-02-05 20:00:02 EST" "2010-02-05 20:00:06 EST"
str(x)
POSIXct[1:4], format: "2010-02-05 20:00:01" "2010-02-05 20:00:02" ... On Fri, Oct 1, 2010 at 1:59 AM, rajeshj at cse.iitm.ac.in
<rajeshj at cse.iitm.ac.in> wrote:
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")})
This gives me a list that looks like this...
[[1]]
[1] "2010-02-05 20:00:01.43"
[[2]]
[1] "2010-02-05 20:00:02.274"
[[3]]
[1] "2010-02-05 20:00:02.274"
[[4]]
[1] "2010-02-05 20:00:06.34"
However, when I do an unlist...I gets converted to something like this...
sec ? ? ?min ? ?hour ? ?mday ? ? mon ? ?year ? ?wday ? ?yday ? isdst ? ? sec ? ? min ? ?hour ? ?mday ? ? mon ? ?year ? ?wday ? ?yday ? isdst ? ? sec
?1.430 ? 0.000 ?20.000 ? 5.000 ? 1.000 110.000 ? 5.000 ?35.000 ? 0.000 ? 2.274 ? 0.000 ?20.000 ? 5.000 ? 1.000 110.000 ? 5.000 ?35.000 ? 0.000 ? 2.274
? ?min ? ?hour ? ?mday ?mon ? ?year ? ?wday ? ?yday ? isdst ? ? sec ? ? min ? ?hour ? ?mday ? ? mon ? ?year ? ?wday ? ?yday ? isdst
?0.000 ?20.000 ? 5.000 ? 1.000 110.000 ? 5.000 ?35.000 ? 0.000 ? 6.340 ? 0.000 ?20.000 ? 5.000 ? 1.000 110.000 ? 5.000
I want it to become a dataframe column except for a change in the datatype to datetime...how can I achieve this?
? ? ? ?[[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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101001/dae28628/attachment.pl>
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101004/ca8beaf9/attachment.pl>