This feels like it should be easier than it is but here we go. I have a data frame that looks like this:
df = structure(list(geography = c("030223131022122122", "030223131220201023",
"030223131023121330", "030223131212130201", "030223131202323120",
"030223131202033333", "030223131202003223", "030223131200111131",
"030223131032003101", "030223131020030220"), xlon = c(-79.403,
-79.44008, -79.30138, -79.20937, -79.39201, -79.40987, -79.44008,
-79.36592, -79.2588, -79.43047), xlat = c(43.87067, 43.67234,
43.87562, 43.75076, 43.71305, 43.73985, 43.75572, 43.83205, 43.88948,
43.93895), bounds = c("-79.40369,43.87018,-79.40231,43.87117",
"-79.44077,43.67184,-79.43939,43.67284", "-79.30206,43.87513,-79.30069,43.87612",
"-79.21005,43.75027,-79.20868,43.75126", "-79.39270,43.71256,-79.39133,43.71355",
"-79.41055,43.73935,-79.40918,43.74034", "-79.44077,43.75523,-79.43939,43.75622",
"-79.36661,43.83155,-79.36523,43.83255", "-79.25949,43.88899,-79.25812,43.88998",
"-79.43115,43.93845,-79.42978,43.93944"), start_date = c("2021-07-01",
"2021-07-01", "2021-07-01", "2021-07-01", "2021-07-01", "2021-07-01",
"2021-07-01", "2021-07-01", "2021-07-01", "2021-07-01"), end_date = c("2021-07-31",
"2021-07-31", "2021-07-31", "2021-07-31", "2021-07-31", "2021-07-31",
"2021-07-31", "2021-07-31", "2021-07-31", "2021-07-31"), agg_day_period = c(1L,
1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L), agg_time_period = c(20L,
22L, 20L, 6L, 14L, 22L, 7L, 16L, 21L, 7L), activity_index_total = c(0.018224,
0.020511, 0.070478, 0.054159, 0.037204, 0.036961, 0.046656, 0.415398,
0.017664, 0.029587)), row.names = c(770468L, 955885L, 621962L,
1164473L, 479957L, 588295L, 61790L, 1338380L, 1225032L, 688909L
), class = "data.frame")
I want to create filtered data frames by subsetting hours that represent different times of data. Here are two examples:
wd_1_5 <- c(1:5)
wd_6_9 <- c(6:9)
I want to loop through a whole bunch of these and filter my tibble, which I then plan on turning into rasters. How can I do this in a loop? Or is there a more effective way to do this?
Here’s what I’ve been currently trying:
time.periods < c(wd_1_5, wd_6_9)
for(i in time.periods){
df = to.csv %>%
filter(agg_day_period == 1, agg_time_period %in% i) %>%
group_by(geography, bounds)
print(unique(df$agg_time_period))
}