[R] identify time span in date vector
David Winsemius
dwinsemius at comcast.net
Tue Apr 3 19:08:08 CEST 2012
On Apr 3, 2012, at 9:35 AM, Fischer, Felix wrote:
> Hello everyone,
>
> i try to identify the first element of a date vector, for which the
> following condition holds: at least 3 more dates within the next 365
> days, but at least one of these must be between 3-12 month later.
>
> dates = as.Date(sort(rnorm(10,3000,100)), origin = "2000-1-1")
>
> Has anyone an idea how to do this economically? I'll need to apply
> this to a large dataset with date vectors of various lengths and I
> can think only of quite difficult algorithms :(
>
which( dates[4:(length(dates))] -dates[1:(length(dates)-3)] <365 &
dates[3:(length(dates)-1)] -dates[1:(length(dates)-3)] > 90)
[1] 2 3
> Any ideas would be appreciated,
> Felix
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list