[R] irregular sequence of events
Sarah Goslee
sarah.goslee at gmail.com
Fri Feb 20 15:42:10 CET 2015
Hi,
On Fri, Feb 20, 2015 at 9:27 AM, PIKAL Petr <petr.pikal at precheza.cz> wrote:
> Dear all
>
> I know I am missing something obvious but after few hours of trials I ask for some help.
>
> I have some sequence of values (days)
> x <- 1:30
>
> and an indication of event start and end day
> mimo<-c(5,10, 13,16, 21,27)
> cut(x, mimo)
[1] <NA> <NA> <NA> <NA> <NA> (5,10] (5,10] (5,10] (5,10]
[10] (5,10] (10,13] (10,13] (10,13] (13,16] (13,16] (13,16] (16,21] (16,21]
[19] (16,21] (16,21] (16,21] (21,27] (21,27] (21,27] (21,27] (21,27] (21,27]
[28] <NA> <NA> <NA>
Levels: (5,10] (10,13] (13,16] (16,21] (21,27]
should get you started. You'll need to tweak the arguments to get
exactly what you want,
> or
>
> events <- structure(list(start = c(5, 13, 21), end = c(10, 16, 27)), .Names = c("start",
> "end"), row.names = c(NA, -3L), class = "data.frame")
>
> I need to get a factor indicating event
>
> event <- c(rep(NA, 4), rep("A1", 6), rep(NA, 2), rep("A2", 4), rep(NA, 4), rep("A3", 7), rep(NA,3))
> factor(event)
>
> In such small example I can do it manually but I have a long vector of dates and would like to use start and end day of events either from mimo vector or from events data frame.
>
> Is there any function which does it automagically? I know I have seen it before but I cannot find it now.
>
> Best regards
> Petr
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list