Message-ID: <1393630341.97544.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2014-02-28T23:32:21Z
From: arun
Subject: (no subject)
In-Reply-To: <1393626454.79967.YahooMailNeo@web141704.mail.bf1.yahoo.com>
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.