PLEASE HELP I have a named list of 152 elements(daily values), each having 12 columns, I wish to create a new list with the sum/aggregate of the values of the column 11 year-wise...(the 12th column in my original contains the year-this is the daily dataset of sediment at 152 stations)
Are you looking for something like this? I invented a small data set with only two stations and two years of each but the process should work on large data sets.
library(tidyverse)
DF1 <- data.frame(A = rnorm(8), Value = 1:8, Year = rep(c(1971,1972),4))
DF2 <- data.frame(A = rnorm(8), Value = 11:18, Year = rep(c(1971,1972),4))
MasterList = list(Station1 = DF1, Station2 = DF2)
MyFunc <- function(DF) {
DF |> group_by(Year) |> summarize(Aggreg = sum(Value))
}
SumList <- map(MasterList, MyFunc)
SumList
$Station1
# A tibble: 2 x 2
Year Aggreg
<dbl> <int>
1 1971 16
2 1972 20
$Station2
# A tibble: 2 x 2
Year Aggreg
<dbl> <int>
1 1971 56
2 1972 60