What's wrong with manipulating the results arun got?

dat3<-read.table(text="
Begin_date                          End_date
01JAN2000:00:00:00:000      02FEB2002:00:00:00:000
24MAR2012:00:00:00:000      18MAY2012:00:00:00:000
01OCT2003:00:00:00:000      02FEB2004:00:00:00:000
01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
",sep="",header=TRUE)

dat3$Begin_date<-strptime(dat3[,1],format="%d%b%Y:%H:%M:%S")
dat3$End_date<-strptime(dat3[,2],format="%d%b%Y:%H:%M:%S")

# difference in days
result <- difftime(dat3[,1],dat3[,2])

# difference in seconds
ddays <- as.numeric(result/(24*3600))
ddays

HTH,
Jorge.-


On Tue, Jul 10, 2012 at 3:55 PM, C W <> wrote:

> When the days and time are identical, difftime() gives difference in secs.
>  I still want difference in days.
>
> Say, below my last row is identical
> dat3<-read.table(text="
> Begin_date                          End_date
> 01JAN2000:00:00:00:000      02FEB2002:00:00:00:000
> 24MAR2012:00:00:00:000      18MAY2012:00:00:00:000
> 01OCT2003:00:00:00:000      02FEB2004:00:00:00:000
> 01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
> 01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
> 24DEC2012:00:00:00:000      24DEC2012:00:00:00:000
> ",sep="",header=TRUE)
>
> -M
>
> On Tue, Jul 10, 2012 at 1:52 PM, arun <smartpink111@yahoo.com> wrote:
>
> > Hi,
> >
> > Try this:
> >
> > dat3<-read.table(text="
> > Begin_date                          End_date
> > 01JAN2000:00:00:00:000      02FEB2002:00:00:00:000
> > 24MAR2012:00:00:00:000      18MAY2012:00:00:00:000
> > 01OCT2003:00:00:00:000      02FEB2004:00:00:00:000
> > 01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
> > 01JAN2000:00:00:00:000      02FEB2000:00:00:00:000
> > ",sep="",header=TRUE)
> >
> > dat3$Begin_date<-strptime(dat3[,1],format="%d%b%Y:%H:%M:%S")
> > dat3$End_date<-strptime(dat3[,2],format="%d%b%Y:%H:%M:%S")
> >
> >  difftime(dat3[,1],dat3[,2])
> > Time differences in days
> > [1] -763.0000  -55.0000 -124.0417  -32.0000  -32.0000
> > attr(,"tzone")
> > [1] ""
> >
> > A.K.
> >
> > ----- Original Message -----
> > From: C W <tmrsg11@gmail.com>
> > To: r-help <r-help@r-project.org>
> > Cc:
> > Sent: Tuesday, July 10, 2012 1:22 PM
> > Subject: [R] calculating the difference between days?
> >
> > Hi List,
> >
> > I have one column of beginning dates and one column of ending dates, I
> want
> > to find their difference.  And I want to ignore the trailing zeros,
> > basically everything after the first colon mark.
> >
> > Begin_date                           End_date
> > 01JAN2000:00:00:00:000       02FEB2002:00:00:00:000
> > 24MAR2012:00:00:00:000       18MAY2012:00:00:00:000
> > 01OCT2003:00:00:00:000       02FEB2004:00:00:00:000
> > 01JAN2000:00:00:00:000       02FEB2000:00:00:00:000
> > 01JAN2000:00:00:00:000       02FEB2000:00:00:00:000
> >
> > Thanks,
> >
> > Mike
> >
> >     [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
> >
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

