I am new to R and having some issues with subsetting my data based on certain criteria. I have five columns (Location, Site, Species, Date, Time).
What I want to do is subset my data based on if the time of the last record is greater than one hour from the previous record of the same date, same species, same site, and same location. If any of the previous columns are not the same as the previous I want it to ignore it and move on.
As an example, this dataframe should say that the first two records are independent as all columns previous to the time column are the same and they are = or > than 60mins apart, whereas the last record is 59mins so is not independent.
Location Site Species Date Time
Twelve 2 frog 14-10 13:45
Twelve 2 frog 14-10 14:45
Twelve 2 frog 14-10 15:44
In this example, the first two lines are independent but the third line is a different species, and the line after is the same as the third but is a different location. The fifth line, all the data is the same as the previous line except it again is 59mins apart.
The results from this should return the first two lines (Both independent of each other), the third line as it is independent of the line before and line after (As the species is different from the line before, and different location to the line after), and then just the fourth line as it is independent of the line before, the last line should not show on the subset of data as it is not independent of the line before (<60mins apart).
Location Site Species Date Time
Twelve 2 frog 14-10 13:45
Twelve 2 frog 14-10 14:45
Twelve 2 badger 14-10 15:44
Thirteen 2 badger 14-10 16:44
Thirteen 2 badger 14-10 17:42
Aucun commentaire:
Enregistrer un commentaire