[R] date calculation
Shi, Tao
shidaxia at yahoo.com
Sat Oct 30 07:59:03 CEST 2010
Hi Phil,
Thanks for the reply, but I don't think you have
explained where the decimal part is coming from....
...Tao
----- Original Message -----
> From:Phil Spector <spector at stat.berkeley.edu>
> To:"Shi, Tao" <shidaxia at yahoo.com>
> Cc:r-help at stat.math.ethz.ch
> Sent:Friday, October 29, 2010 5:04:23 PM
> Subject:Re: [R] date calculation
>
>
> Tao -
The documentation for the difftime function
> says:
Function ‘difftime’ calculates a difference of two
> date/time
objects and returns an object of class
> ‘"difftime"’ with an
attribute indicating the
> units.
So that answers your question.
If you want it to be an
> integer, you're certainly free to make it one:
>
> as.integer(difftime(strptime("24NOV2004", format="%d%b%Y"),
+
>
> strptime("13MAY2004",format="%d%b%Y"), units="days"))
[1] 195
>
> - Phil Spector
> Statistical Computing
> Facility
> Department of Statistics
>
> UC Berkeley
>
> ymailto="mailto:spector at stat.berkeley.edu"
> href="mailto:spector at stat.berkeley.edu">spector at stat.berkeley.edu
On
> Fri, 29 Oct 2010, Shi, Tao wrote:
> Hi list,
>
> Could
> someone explain to me why the following result is not a
> integer?
>
>
>> difftime(strptime("24NOV2004",
> format="%d%b%Y"), strptime("13MAY2004",
>> format="%d%b%Y"),
> units="days")
> Time difference of 195.0417 days
>
> I'm using
> R2.12.0 on WinXP.
>
> Thanks!
>
> ...Tao
>
>
> ______________________________________________
>
> ymailto="mailto:R-help at r-project.org"
> href="mailto:R-help at r-project.org">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.
>
More information about the R-help
mailing list