How to identify the records that belong to a certain time interval when I know the start and end records of that interval? (R) -
so, here problem. have dataset of locations of radiotagged hummingbirds i’ve been following part of thesis. might imagine, fly fast there intervals when lost track of until found them again. trying identify segments bird followed continuously (i.e., intervals between “lost” periods).
id type timestart timeend limiter starter ender 1 observed 6:45:00 6:45:00 no start end 2 lost 6:45:00 5:31:00 yes no no 3 observed 5:31:00 5:31:00 no start no 4 observed 9:48:00 9:48:00 no no no 5 observed 10:02:00 10:02:00 no no no 6 observed 10:18:00 10:18:00 no no no 7 observed 11:00:00 11:00:00 no no no 8 observed 13:15:00 13:15:00 no no no 9 observed 13:34:00 13:34:00 no no no 10 observed 13:43:00 13:43:00 no no no 11 observed 13:52:00 13:52:00 no no no 12 observed 14:25:00 14:25:00 no no no 13 observed 14:46:00 14:46:00 no no end 14 lost 14:46:00 10:47:00 yes no no 15 observed 10:47:00 10:47:00 no start no 16 observed 10:57:00 11:00:00 no no no 17 observed 11:10:00 11:10:00 no no no 18 observed 11:19:00 11:27:55 no no no 19 observed 11:28:05 11:32:00 no no no 20 observed 11:45:00 12:09:00 no no no 21 observed 11:51:00 11:51:00 no no no 22 observed 12:11:00 12:11:00 no no no 23 observed 13:15:00 13:15:00 no no end 24 lost 13:15:00 7:53:00 yes no no 25 observed 7:53:00 7:53:00 no start no 26 observed 8:48:00 8:48:00 no no no 27 observed 9:25:00 9:25:00 no no no 28 observed 9:26:00 9:26:00 no no no 29 observed 9:32:00 9:33:25 no no no 30 observed 9:33:35 9:33:35 no no no 31 observed 9:42:00 9:42:00 no no no 32 observed 9:44:00 9:44:00 no no no 33 observed 9:48:00 9:48:00 no no no 34 observed 9:48:30 9:48:30 no no no 35 observed 9:51:00 9:51:00 no no no 36 observed 9:54:00 9:54:00 no no no 37 observed 9:55:00 9:55:00 no no no 38 observed 9:57:00 10:01:00 no no no 39 observed 10:02:00 10:02:00 no no no 40 observed 10:04:00 10:04:00 no no no 41 observed 10:06:00 10:06:00 no no no 42 observed 10:20:00 10:33:00 no no no 43 observed 10:34:00 10:34:00 no no no 44 observed 10:39:00 10:39:00 no no end
note: when there “start” , “end” in same row it’s because non-lost period consists of record.
i able identify records start or end these “non-lost” periods (under columns “starter” , “ender”), want able identify periods giving them unique identifiers (period a,b,c or 1,2,3, etc). ideally, name of identifier name of start point period (i.e., id[ starter==”start”])
i'm looking this:
id type timestart timeend limiter starter ender period 1 observed 6:45:00 6:45:00 no start end 1 2 lost 6:45:00 5:31:00 yes no no lost 3 observed 5:31:00 5:31:00 no start no 3 4 observed 9:48:00 9:48:00 no no no 3 5 observed 10:02:00 10:02:00 no no no 3 6 observed 10:18:00 10:18:00 no no no 3 7 observed 11:00:00 11:00:00 no no no 3 8 observed 13:15:00 13:15:00 no no no 3 9 observed 13:34:00 13:34:00 no no no 3 10 observed 13:43:00 13:43:00 no no no 3 11 observed 13:52:00 13:52:00 no no no 3 12 observed 14:25:00 14:25:00 no no no 3 13 observed 14:46:00 14:46:00 no no end 3 14 lost 14:46:00 10:47:00 yes no no lost 15 observed 10:47:00 10:47:00 no start no 15 16 observed 10:57:00 11:00:00 no no no 15 17 observed 11:10:00 11:10:00 no no no 15 18 observed 11:19:00 11:27:55 no no no 15 19 observed 11:28:05 11:32:00 no no no 15 20 observed 11:45:00 12:09:00 no no no 15 21 observed 11:51:00 11:51:00 no no no 15 22 observed 12:11:00 12:11:00 no no no 15 23 observed 13:15:00 13:15:00 no no end 15 24 lost 13:15:00 7:53:00 yes no no lost
would hard in r?
thanks!
> d <- data.frame(limiter = rep("no", 44), starter = rep("no", 44), ender = rep("no", 44), stringsasfactors = false) > d$starter[c(1, 3, 15, 25)] <- "start" > d$ender[c(1, 13, 23, 44)] <- "end" > d$limiter[c(2, 14, 24)] <- "yes" > d$period <- ifelse(d$limiter == "yes", "lost", which(d$starter == "start")[cumsum(d$starter == "start")]) > d limiter starter ender period 1 no start end 1 2 yes no no lost 3 no start no 3 4 no no no 3 5 no no no 3 6 no no no 3 7 no no no 3 8 no no no 3 9 no no no 3 10 no no no 3 11 no no no 3 12 no no no 3 13 no no end 3 14 yes no no lost 15 no start no 15 16 no no no 15 17 no no no 15 18 no no no 15 19 no no no 15 20 no no no 15 21 no no no 15 22 no no no 15 23 no no end 15 24 yes no no lost 25 no start no 25 26 no no no 25 27 no no no 25 28 no no no 25 29 no no no 25 30 no no no 25 31 no no no 25 32 no no no 25 33 no no no 25 34 no no no 25 35 no no no 25 36 no no no 25 37 no no no 25 38 no no no 25 39 no no no 25 40 no no no 25 41 no no no 25 42 no no no 25 43 no no no 25 44 no no end 25
Comments
Post a Comment