Hi all,
I have a list of some data frames (attached). the name of each element of the list is the date in which the measurements were taken. I also have a vector of the dates called "waf_dates"
I want to summarize each data frame and write the results to one new data frame.
I tried to do that with lapply like this:
library(dplyr)
library(lubridate)
ttl_emsn <- lapply (waf_files, sum_fun)
sum_fun <- function (waf) {
waf %>%
group_by (treat) %>%
summarise (date = ymd (names(waf)),
emission = round (sum (n2o*collar_area), digits = 2), # calculates total flux per treatment
emission_err = round (sqrt (sum ((emsn_err)), digits = 2))
)
}
The problem seems to be with assigning the names to the date column "
date = ymd (names(waf))"
So I tried to do that with a for loop:
for (i in seq_along (waf_files)) {
ttl_emssn <- waf_files [[i]] %>%
group_by (treat) %>%
summarise (date = ymd (waf_dates [i]),
emission = round (sum (n2o*collar_area), digits = 2),
emssn_err = round (sqrt (sum (emission_err)), digits = 2)
)
}
This solved the date issue but only wrote the summary of the last element of the list.When I tried to index ttl_emssn like this :
ttl_emssn [i*3-2,] the whole thing got crazy
Can someone help?