I don't have much experience with R and I am stuck with the following problem: I have data in csv format from radio collared wildcats with datetime stamps and GPS locations (and some additional info as sex,age etc.). I have to balance the datasets for each individual as the frequency of the fixes (locations) is unequal. I want to extract one random position a day for every day of my data, for every cat. In addition, the chosen random points per individual should have a 50/50 ratio of day and night points. For this purpose I created a column defining if the location was recorded during night or day, but I don't know how to add the ratio rule to my code. I also wonder if its possible to save the random chosen points in the code, so if someone else runs it again, they get the same random points as I extracted the first time (I think it can be done with set.seed?). I often just don't know how to combine all the functions I wanna use.
I think I successfully extracted one random point a day per individual with the following code:
data %>% group_by(animals_id,utc) %>%
sample_n(1) -> result
But how can I include the 50/50 ratio of day and night points per Individual and how can I add a set.seed function?
This is the structure of my data set:
X animals_id acquisition_time longitude latitude
1 1 1 2010-05-01 02:59:00 7.604915 47.94362
2 2 1 2010-05-01 10:00:00 7.604967 47.94373
3 3 1 2010-05-01 16:59:00 7.605800 47.94379
4 4 1 2010-05-02 06:59:00 7.604969 47.94358
5 5 1 2010-05-02 13:59:00 7.604921 47.94008
6 6 1 2010-05-03 03:59:00 7.605051 47.94356
projection collar_type study_area_id animals_age_class
1 EPSG:4326-WGS48 gps 13 a
2 EPSG:4326-WGS48 gps 13 a
3 EPSG:4326-WGS48 gps 13 a
4 EPSG:4326-WGS48 gps 13 a
5 EPSG:4326-WGS48 gps 13 a
6 EPSG:4326-WGS48 gps 13 a
animals_sex utc day_night
1 f 2010-05-01 night
2 f 2010-05-01 day
3 f 2010-05-01 day
4 f 2010-05-02 day
5 f 2010-05-02 day
6 f 2010-05-03 night
>
I am very grateful for every tip.