How to define encounter periods by using first and last timestamps within a time series in R -


I work with electronic tagged fish. One snippet of my telemetry data (dataframe "D") is below each timestamp represents an identity for a unique fish. Tag ID Place of inquiry RiverKm 163 02/23/2012 03:17:44 Alcatraz_E 4.414 163 02/23/2012 03:56:25 Alcatraz_E 4.414 163 04/14/2012 15:10 : 20 Alcatraz_E 4.414 163 04/14/2012 15:12:11 Alcatraz_N 4.414 163 03/11/2012 08:59:48 Alcatraz_N 4.414 163 03/11/2012 09:02:15 Alcatraz_N 4.414 163 03/11/2012 09 : 04:05 Alcatraz_N 4.414 163 03/11/2012 09:04:06 Alcatraz_N 4.414 163 03/11/2012 09:06:09 Alcatraz_N 4.414 163 03/11/2012 9:06:11 Alcatraz_A 4.414 < / Pre>

There are several different tags (personal fish). I want to classify detections for every fish during the encounter period by identifying a start time ("arrival") and an expiry time ("departure"), with an important value of 1 hour. For example, for the above fish (Tag ID 163), the output will be:

  Tagged Arrival Departure Location RiverKm 163 02/23/2012 03:17:44 02/23/2012 03: 56 : 25 Alcatraz_E 4.414 163 04/14/2012 15: 10: 2 04/14/2012 15:12:11 Alcatraz_N 4.414 163 03/11/2012 08:59:48 03/11/2012 09:06:11 Alcatraz_E 4.414   

I would like to create a loop (or any other code structure) which does the following:

  for 1 in j: length (unique (d $ Tag ID)   
  1. Identify the time of first identification ("T1")
  2. if in the time limit In addition to session next identification tag ( "T2") T1 is less than an hour, make sure you leave it and continue the next identity; Otherwise, place T1 in the "Arrival" vector and T2 in the "Exit" vector.
  3. Pause when every arrival and departure timestamp is classified for each tag ID.

    I do not know how to do it in the most effective way, and greatly appreciate your help.

    Thank you!

    You must first order your data according to the date. This is why you should convert your detection variable to a valid arbitrary type: POSIXct. Once you have ordered your data, diff , and cumsum you can create a grouping variable to find a leap: here at least one hour (60 minutes) ) Has made a leap after. I am using data.table in the Chinese syntax in Grouping Operations but this is not particularly important if you do not have a loose amount of data.

    My complete code here:

      Library (data.table) ## Data Corsean D $ Detection & lt; - as.POSIXct (Striptime (D $ detection, '% m /% d /% Y% H:% M:% S')) ## Sort by using Tecetion d & lt; -d [Order (D $ detection), # ID variable is incremented, which is a one hour D $ id & lt; - Detects the jump of cumsum (C (F, round (D $ detection) / 60) & Gt; 60) ## You do not mention to select the place, Set DT (D) [, list (start = check [1], end = investigation [length (probe)], location = location [1], rivercom = rivercover [1], "tag id, id" # # tag id End of ID RiverCurm # 1: 163 0 2012-02-23 03:17:44 2012-02-23 03: 56: 25 Alcatraz_E 4.414 # 2: 163 1 2012-03-11 08:59:48 2012-03 -11 09:06:11 Alcatraz_N 4.414 # 3: 163 2 2012-04-14 15:10:20 2012- 04-14 15:12:11 Alcal Trajh_a 4.414    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -