0

I have a dataframe with the relocations of an animal obtained with a GPS collar. The collar was on the animal for 43 days. I want to evaluate the evolution of the weekly (7days) home range over the the total time of monitoring by a moving window with step of one day.

Here is the first lines of my dataframe:

>head(hodor)
devil       date  time             Tfix fixid ttf Northing Easting alt Maxsnr Hdop sat qual  temp day
1 hodor 12/08/2015 14:00 2015/08/12 14:00    21  97       NA      NA   0      0  0.0   0   NO 34.25   1
2 hodor 12/08/2015 17:00 2015/08/12 17:00    22  97       NA      NA   0      0  0.0   0   NO 34.31   1
3 hodor 12/08/2015 18:00 2015/08/12 18:00    23  97       NA      NA   0      0  0.0   0   NO 30.37   1
4 hodor 12/08/2015 19:00 2015/08/12 19:00    24  74  5343138  598559  14     41  1.2   8   3D 21.31   1
5 hodor 12/08/2015 20:00 2015/08/12 20:00    25  39  5342985  598631  11     39  1.1  10   3D 30.50   1
6 hodor 12/08/2015 21:00 2015/08/12 21:00    26  39  5342202  598873   4     42  1.3   8   3D 20.25   1

The full data set contain 1052 lines and the column "date" has 43 levels I have created a column "day" with values from 1 to 43 corresponding to the levels of "date"

This is the outcome I want to have:

df1 <- hodor[(hodor$day >= 1 & hodor$day <= 7),]
df2 <- hodor[(hodor$day >= 2 & hodor$day <= 8),]
df3 <- hodor[(hodor$day >= 3 & hodor$day <= 9),]
...
df37 <- hodor[(hodor$day >= 37 & hodor$day <= 43),]
lst <- list(df1, df2, df3, ... , df37)

Is there an easy way to do that without creating each line manually?

I have found several questions about splitting dataframes, but it usually relies on a unique value of a factor. In my case, each extracted dataframe has a lot of overlapping with the others.

Thank you for your help

  • Please provide a minimal reproducible example as explained [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – tobiasegli_te Oct 26 '17 at 07:47

1 Answers1

0

Here is a quick way of doing it with lapply:

lst <- lapply(1:(max(hodor$day) - 6), function(x) hodor[hodor$day %in% (x + 0:6), ])
Ashley Baldry
  • 850
  • 9
  • 23