Goal
I am trying to take my data frame, with nested data in the sac_EV column, and check the sampling rate variable to determine if I need to remove every other row from the unnested data. If the sampling_rate == 100 then I want to leave it alone. If the sampling_rate is 200 I want to get rid of every other row, essentially making it equivalent in size to the 100 sampling rate sets. I know this should be super simple, but for the life of me, I can't think of a simple function that will grab every other row that I can cleanly implement into my piping. Any and all help is greatly appreciated.
Data
I think this URL will automatically download the RDS file from my repository when you put it in your browser,
https://gitlab.com/Bryanrt-geophys/sac2eqtransformr/-/raw/master/sample_data/pre_hdf5.rds
If not, here is a small portion of the data unnested
pre_hdf5 <- read_csv(file = "https://gitlab.com/Bryanrt-geophys/sac2eqtransformr/-/raw/master/sample_data/pre_hdf5_resampling_reprex.csv", col_names = T)
Starting Point/REPREX
pre_hdf5_unnested <- pre_hdf5 %>%
unnest(cols = c(sac_EV))
pre_hdf5_unnested %>%
group_by(event, reciever_code) %>%
group_split() %>%
map(.f = function(x){
x %>% mutate(
id = row_number()
) %>%
if(x$sampling_rate == 200){
if((x$id %% 2) == 0) {
rows_delete()
}
}
})