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
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.