[R] middle of interval
    Duncan Murdoch 
    murdoch.duncan at gmail.com
       
    Mon Feb  8 11:17:06 CET 2016
    
    
  
On 08/02/2016 5:09 AM, catalin roibu wrote:
> Dear R users!
>
> I have a data frame with first column is an interval (1902-1931) and I want
> to find the middle of the interval? Is there a possibility to do that in R?
>
> Thank you very much!
>
> Best regards!
>
I don't know of a single function that does that, but the way to do it 
would be to separate the interval into two numbers, then take the 
average.  If your intervals are strings in the form shown above (not 
including the parentheses), this would work:
interval <- "1902-1931"
start <- as.numeric(sub("-.*", "", interval))
stop  <- as.numeric(sub(".*-", "", interval))
(start + stop)/2
Duncan Murdoch
    
    
More information about the R-help
mailing list