[R] (no subject)
arun
smartpink111 at yahoo.com
Sat Mar 1 00:32:21 CET 2014
HI Farnoosh,
Try:
D1= c("5/25/2012 14:48", "5/29/2012 16:53", "6/1/2012 18:30")
D2= c("6/8/2012 21:26", "6/11/2012 15:10" , "6/14/2012 17:57")
as.numeric(as.POSIXct(D2,format="%m/%d/%Y %H:%M")-as.POSIXct(D1,format="%m/%d/%Y %H:%M")) #days
#[1] 14.27639 12.92847 12.97708
#or
as.numeric(difftime(as.POSIXct(D2,format="%m/%d/%Y %H:%M"),as.POSIXct(D1,format="%m/%d/%Y %H:%M"),units="days"))
#[1] 14.27639 12.92847 12.97708
A.K.
On Friday, February 28, 2014 5:27 PM, farnoosh sheikhi <farnoosh_81 at yahoo.com> wrote:
Hi,
I have a two column with date/time format like below:
D1= ( 5/25/2012 14:48, 5/29/2012 16:53, 6/1/2012 18:30).
D2= (6/8/2012 21:26, 6/11/2012 15:10 , 6/14/2012 17:57)
I want to subtract D1-D2 and obtain the difference between them.
I have tried as.date and as.numeric, but the values convert to NAs.
Thanks for your help.
More information about the R-help
mailing list