[R] date calculation
Phil Spector
spector at stat.berkeley.edu
Sat Oct 30 02:04:23 CEST 2010
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
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
>
> ______________________________________________
> 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