I have two dataframes, the first (df1) only with dates and the second (df2) with dates and values -> see example.
I want to create a third dataframe (df3) with the dates from df1 where the values from df2 are averaged in the period between the dates from df1.
Unfortunatly there is no structured continuity of the dates.
So the result should be:
1986-01-15 NA
1986-01-20 (6+8+1)/3 = 5
1986-01-24 (7+3+9+1)/4 = 5
1986-01-28 (4+5)/2 = 4,5
df1 <- data.frame(
Date = c(
"1986-01-15",
"1986-01-20",
"1986-01-24",
"1986-01-28"
)
)
View(df1)
df2 <- data.frame(
Date = c(
"1986-01-16",
"1986-01-17",
"1986-01-20",
"1986-01-21",
"1986-01-22",
"1986-01-23",
"1986-01-24",
"1986-01-27",
"1986-01-28"
),
Value = c(6,8,1,7,3,9,1,4,5)
)
View(df2)
I hope someone can help. Thank youu!!