Readers, For a 12 hour time stamp:> testtime<-("2013-01-01 01:00:01 PM") > testtime[1] "2013-01-01 01:00:01 PM"> testtime24hour<-strftime(testtime,'%H:%M:%S') > testtime24hour[1] "01:00:01" how to convert to 24 hour format so that the object 'testtime24hour' is: '13:00:01' Thanks. -- r2151
Hello, Try this: > testtime<-("2013-01-01 01:00:01 PM") > strptime(testtime, "%Y-%m-%d %I:%M:%S %p") [1] "2013-01-01 13:00:01" HTH, Pascal Le 08/02/2013 18:44, e-letter a ?crit :> Readers, > > For a 12 hour time stamp: > >> testtime<-("2013-01-01 01:00:01 PM") >> testtime > [1] "2013-01-01 01:00:01 PM" >> testtime24hour<-strftime(testtime,'%H:%M:%S') >> testtime24hour > [1] "01:00:01" > > how to convert to 24 hour format so that the object 'testtime24hour' is: > > '13:00:01' > > Thanks. > > -- > r2151 > > ______________________________________________ > 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. >
Hi, library(lubridate) ?ymd_hms(testtime) ?1 parsed with %Y-%m-%d %I:%M:%S %p #[1] "2013-01-01 13:00:01 UTC" A.K. ----- Original Message ----- From: e-letter <inpost at gmail.com> To: r-help at r-project.org Cc: Sent: Friday, February 8, 2013 4:44 AM Subject: [R] convert 12 time stamp to 24 hour Readers, For a 12 hour time stamp:> testtime<-("2013-01-01 01:00:01 PM") > testtime[1] "2013-01-01 01:00:01 PM"> testtime24hour<-strftime(testtime,'%H:%M:%S') > testtime24hour[1] "01:00:01" how to convert to 24 hour format so that the object 'testtime24hour' is: '13:00:01' Thanks. -- r2151 ______________________________________________ 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.
On 08/02/2013, e-letter <inpost at gmail.com> wrote:> Readers, > > For a 12 hour time stamp: > >> testtime<-("2013-01-01 01:00:01 PM") >> testtime > [1] "2013-01-01 01:00:01 PM" >> testtime24hour<-strftime(testtime,'%H:%M:%S') >> testtime24hour > [1] "01:00:01" >Have realised that the object is of type 'character'. When this conversion is applied to a vector and then the 'plot' function applied (i.e. plot another vector against the vector of 24-hour time series values), receive an error. How to convert the values "01:00:01" to 'ts' objects?
Readers, Have since tried to plot converted 24 hour data: testtimedataset V1 1 13:01:41 2 13:02:10 3 13:02:38 4 13:03:05 5 13:03259> testdata<-seq(1:5) > plot(testdata~testtimedataset)Error in function (formula, data = NULL, subset = NULL, na.action = na.fail, : invalid type (list) for variable 'testtimedataset' Was expecting to see a graph with ordinate values 1:5 for the time series values on the abscissa. What is the mistake please? -- r2151