Getting the numeric value of difftime

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting the numeric value of difftime

Christian Neumann
Hi folks,

I have a small, maybe newbie, question concerning date operations.
The follwing snippet

date1 = "2005-11-20";
date2 = "2005-11-17";
difftime(date1, date2)

results in "Time difference of 3 days". How can I extract just the
numerical value 3?
As a workaround I apply mean() on the result which gives me just a
numerical value.

Thanks a lot,

Christian

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Getting the numeric value of difftime

barry rowlingson
Christian Neumann wrote:

> Hi folks,
>
> I have a small, maybe newbie, question concerning date operations.
> The follwing snippet
>
> date1 = "2005-11-20";
> date2 = "2005-11-17";
> difftime(date1, date2)
>
> results in "Time difference of 3 days". How can I extract just the
> numerical value 3?
> As a workaround I apply mean() on the result which gives me just a
> numerical value.

  If you want to get one thing _as_ another the R-ish solution is nearly
always to do as.another(oneThing).

  You want it numeric? You got it!

 > date1 = "2005-11-20";
 > date2 = "2005-11-17";
 > difftime(date1, date2)
Time difference of 3 days
 > as.numeric(difftime(date1, date2))
[1] 3

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Getting the numeric value of difftime

Gabor Grothendieck
In reply to this post by Christian Neumann
This was just discussed two days ago:

https://www.stat.math.ethz.ch/pipermail/r-help/2006-January/084453.html

On 1/13/06, Christian Neumann <[hidden email]> wrote:

> Hi folks,
>
> I have a small, maybe newbie, question concerning date operations.
> The follwing snippet
>
> date1 = "2005-11-20";
> date2 = "2005-11-17";
> difftime(date1, date2)
>
> results in "Time difference of 3 days". How can I extract just the
> numerical value 3?
> As a workaround I apply mean() on the result which gives me just a
> numerical value.
>
> Thanks a lot,
>
> Christian
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Getting the numeric value of difftime

Dimitris Rizopoulos
In reply to this post by Christian Neumann
just try

as.numeric(difftime(date1, date2))


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message -----
From: "Christian Neumann" <[hidden email]>
To: <[hidden email]>
Sent: Friday, January 13, 2006 2:05 PM
Subject: [R] Getting the numeric value of difftime


> Hi folks,
>
> I have a small, maybe newbie, question concerning date operations.
> The follwing snippet
>
> date1 = "2005-11-20";
> date2 = "2005-11-17";
> difftime(date1, date2)
>
> results in "Time difference of 3 days". How can I extract just the
> numerical value 3?
> As a workaround I apply mean() on the result which gives me just a
> numerical value.
>
> Thanks a lot,
>
> Christian
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html