I'm trying to summarize hourly measurement data to daily data for every element in a list.
List looks like this:
SE104:List of 3 ..$ d20:List of 11 .. ..$ 2009:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2009-01-01""2009-01-01""2009-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2010:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2010-01-01""2010-01-01""2010-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2011:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2011-01-01""2011-01-01""2011-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2012:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2012-01-01""2012-01-01""2012-01-01" ... .. .. ..$ SWC : num [1:8784] 43.1 43 42.8 42.7 42.7 ... .. ..$ 2013:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2013-01-01""2013-01-01""2013-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2014:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2014-01-01""2014-01-01""2014-01-01" ... .. .. ..$ SWC : num [1:8760] 37.2 37.2 37.3 37.2 37.1 ... .. ..$ 2015:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2015-01-01""2015-01-01""2015-01-01" ... .. .. ..$ SWC : num [1:8760] 37.3 37.3 37.3 37.3 37.3 ... .. ..$ 2016:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2016-01-01""2016-01-01""2016-01-01" ... .. .. ..$ SWC : num [1:8784] 36 36 36 36 35.9 ... .. ..$ 2017:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2017-01-01""2017-01-01""2017-01-01" ... .. .. ..$ SWC : num [1:8760] 32.9 32.9 32.9 32.9 32.9 ... .. ..$ 2018:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2018-01-01""2018-01-01""2018-01-01" ... .. .. ..$ SWC : num [1:8760] 35 35.1 35.2 35.2 35.2 ... .. ..$ 2019:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2019-01-01""2019-01-01""2019-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN ... ..$ d50:List of 11 .. ..$ 2009:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2009-01-01""2009-01-01""2009-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2010:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2010-01-01""2010-01-01""2010-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2011:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2011-01-01""2011-01-01""2011-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2012:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2012-01-01""2012-01-01""2012-01-01" ... .. .. ..$ SWC : num [1:8784] 39.8 39.6 39.4 39.3 39.3 ... .. ..$ 2013:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2013-01-01""2013-01-01""2013-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2014:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2014-01-01""2014-01-01""2014-01-01" ... .. .. ..$ SWC : num [1:8760] 32.7 32.7 32.8 32.7 32.7 ... .. ..$ 2015:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2015-01-01""2015-01-01""2015-01-01" ... .. .. ..$ SWC : num [1:8760] 33.2 33.2 33.2 33.2 33.2 ... .. ..$ 2016:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2016-01-01""2016-01-01""2016-01-01" ... .. .. ..$ SWC : num [1:8784] 31.9 31.9 31.9 31.9 31.9 ... .. ..$ 2017:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2017-01-01""2017-01-01""2017-01-01" ... .. .. ..$ SWC : num [1:8760] 27.9 27.9 27.9 27.9 27.9 ... .. ..$ 2018:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2018-01-01""2018-01-01""2018-01-01" ... .. .. ..$ SWC : num [1:8760] 29.2 29.2 29.2 29.2 29.2 ... .. ..$ 2019:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2019-01-01""2019-01-01""2019-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN ... ..$ d5 :List of 11 .. ..$ 2009:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2009-01-01""2009-01-01""2009-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2010:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2010-01-01""2010-01-01""2010-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2011:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2011-01-01""2011-01-01""2011-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2012:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2012-01-01""2012-01-01""2012-01-01" ... .. .. ..$ SWC : num [1:8784] 58.4 58.4 58.3 58.2 58.2 ... .. ..$ 2013:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2013-01-01""2013-01-01""2013-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2014:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2014-01-01""2014-01-01""2014-01-01" ... .. .. ..$ SWC : num [1:8760] 47.4 47.4 47.4 47.4 47.4 ... .. ..$ 2015:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2015-01-01""2015-01-01""2015-01-01" ... .. .. ..$ SWC : num [1:8760] 49 49.1 49 49.1 49.1 ... .. ..$ 2016:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format: "2016-01-01""2016-01-01""2016-01-01" ... .. .. ..$ SWC : num [1:8784] 43.7 43.7 43.7 43.8 43.7 ... .. ..$ 2017:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2017-01-01""2017-01-01""2017-01-01" ... .. .. ..$ SWC : num [1:8760] 39.1 39.2 39.1 39.2 39.2 ... .. ..$ 2018:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2018-01-01""2018-01-01""2018-01-01" ... .. .. ..$ SWC : num [1:8760] 45.8 46 46 45.9 45.7 ... .. ..$ 2019:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2019-01-01""2019-01-01""2019-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN ... $ SE105:List of 3 ..$ d20:List of 11 .. ..$ 2009:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2009-01-01""2009-01-01""2009-01-01" ... .. .. ..$ SWC : num [1:8760] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... .. ..$ 2010:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2010-01-01""2010-01-01""2010-01-01" ... .. .. ..$ SWC : num [1:8760] 45.4 45.2 45 44.9 44.8 ... .. ..$ 2011:'data.frame': 8760 obs. of 2 variables: .. .. ..$ Date: Date[1:8760], format: "2011-01-01""2011-01-01""2011-01-01" ... .. .. ..$ SWC : num [1:8760] 39.6 39.6 39.6 39.6 39.6 ... .. ..$ 2012:'data.frame': 8784 obs. of 2 variables: .. .. ..$ Date: Date[1:8784], format:
So you can see that my list has multiple levels. First level is a large list that contains 150 lists. Each list of those 150 lists contains 3 lists (d20, d50, d5) which contain 11 dataframes for each year from 2009-2019.
Each dataframe stored in the list looks like this:
structure(list(Date = structure(c(14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14245, 14246, 14246, 14246, 14246, 14246, 14246), class = "Date"), SWC = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN)), row.names = c(NA, 30L), class = "data.frame")
I want to summarize the data so that I get one value for each day, I was able to do this for just one dataframe that I subsetted but I can't do it for every element in the list. I think I have to use lapply() but I can't figure out how to do it. This is what it should look like:
Date mean_SWC1 2009-01-01 NaN2 2009-01-02 NaN
I'd appreciate some help! A user helped me out with the lapply() function in another question already but it looks like I didn't understand how to use it, as I can't do it here. So in case someone can help and does indeed use lapply() I'd appreciate if one could explain it to me.