I have a list of years, that it loops through and iterate & generate answers for new column in the data frame. But the final results only show the last iteration.
How can I generate/save all the columns and rows in a data frame?
# list of years
years = as.list(unique(as.character(temp_reshape$Year)))
for (i in seq_along(years)) {
# iterate by year
year_index <- years[[i]]
tt <- temp_reshape %>%
filter(as.character(Year) == year_index) %>%
arrange(Date_Value) %>%
mutate(Xt_mu = Value - summer_means,
Xt_u_C = Xt_mu - 0,
St = cumsum(ifelse(Xt_u_C < 0, 0, Xt_u_C)))
}