mardi 24 mars 2020

R function to determine if row in time series is differnt from previous and extract both rows from list

I have a list of 14 individual organisms from a telemetry dataset tracking their movements. I'm interested in figuring out if they have crossed a few specific barriers at any point during the monitoring period. These 14 individuals are currently stored in a list and have detections ranging from 100's to 100,000's of detections.

An example to the dataset is below:

Date        Time      Individual      Location
2019-04-25  06:16:29  A69-1601-26907  DI 03
2019-04-25  06:23:31  A69-1601-26907  DI 03
2019-04-25  06:52:17  A69-1601-26907  BR 04
2019-04-25  07:41:31  A69-1601-26907  BR 04
2019-04-25  07:59:13  A69-1601-26907  BR 04
2019-04-25  08:16:19  A69-1601-26907  DI 03
2019-04-25  08:33:42  A69-1601-26907  DI 03

The goal would be to extract the two rows where the location has changed. For example, BR 04 and the one just before it (06:23:31 and 06:52:17 rows) and put them in their own dataframe. Then to also to extract the rows at 7:59:13 and 8:16:19 since it signifies that this individual crossed the barrier again. Doing this for the whole dataset for this individual. Eventually getting a dataframe of all the transits for that one individual.

Then to do that same function again for the other 13 individuals in the list. They can either be appended all to the same dataframe or be in their own in a list.

I've tried to use a for loop with ifelse statements, but it doesn't return anything.

Thanks!

Aucun commentaire:

Enregistrer un commentaire