[R] median time period

From: Iain Gallagher <iaingallagher_at_btopenworld.com>
Date: Wed, 29 Jun 2011 16:24:55 +0100 (BST)

Hello List

I'm trying to calculate the median period (in months) of a set of time intervals (between two interventions).

I have been playing with the lubridate package to create the intervals but I can't think of the right approach to get the median timeperiod.

Toy code:

test <- c('08-04-22', '08-07-28', '09-03-02', '09-03-03', '09-01-30', '09-03-09', '10-02-24', '10-03-05') test <- ymd(test)
intervals <- as.period(test[5:8] - test[1:4])

[1] 9 months and 8 days 7 months and 9 days 11 months and 22 days
[4] 1 year and 2 days

How can I convert this 'period' object to months? From there I think I should just convert to 'numeric' and calculate the median.

Garrett if you're out there - great package but could you help please!?



> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-linux-gnu (64-bit)


 [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8    
 [5] LC_MONETARY=C             LC_MESSAGES=en_GB.utf8   
 [7] LC_PAPER=en_GB.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] lubridate_0.2.4

loaded via a namespace (and not attached):
[1] plyr_1.5.2 stringr_0.4

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. Received on Wed 29 Jun 2011 - 15:34:55 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 29 Jun 2011 - 17:40:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive