Creating a loop for date ranges to calculate their sd in R

Viewed 28

I have this big data.table with specific bihourly measurements. There are a lot of data, from May to September of 2021. All the timestamp are of the POSIXct class, all the date of the date class. I want to create a loop that takes the values of a specific date, for example 2021-05-03 and calculates the standard deviation for the movement done on that day.

> head(dwn_tracks_350)
   bird_ID              timestamp          date       latitude       longitude  
1:    350E    2021-05-01 00:04:42    2021-05-01       62.82922        37.62062
2:    350E    2021-05-01 02:01:52    2021-05-01       62.82932        37.62049 
3:    350E    2021-05-01 03:53:57    2021-05-01       62.95656        37.86326 
4:    350E    2021-05-01 05:47:04    2021-05-01       63.54083        38.86444 
5:    350E    2021-05-01 07:40:29    2021-05-01       63.94228        39.62696 
6:    350E    2021-05-01 09:32:53    2021-05-01       63.94148        39.62709  

I cannot use a function that takes the first 12 rows, and then the next 12 rows, because the data are not standardized that way. Some days have 12, other 11 and other 10 timestamps.

I want the final result to be a data.table or data.frame that has 2 different columns, corresponding to the sd(lat) and sd(long) for each day.

Any idea would be really helpful.

1 Answers
Related