Hi,
I've got data in the wide format such as:
df <- structure(list(ID = c(53155, 53163, 53198, 54771, 55069, 55107, 55166, 55301, 55468, 56324),
`A_from` = c("01/10/2019",NA, "01/10/2016", NA, NA, "01/10/2020", NA, NA, "01/10/2022", NA),
`A_until` = c("01/10/2021", NA, "30/06/2018", NA, NA, "01/10/2022", NA, NA, "01/10/2024", NA),
`A_value` = c(35, NA, 0, NA, NA, 40, NA, NA, 10, NA),
`B_from` = c(NA, NA, "01/09/2018", NA, NA, NA, NA, NA, NA, "01/10/2020"),
`B_until` = c(NA, NA, "30/11/2022", NA, NA, NA, NA, NA, NA, "01/10/2022"),
`B_value` = c(NA,NA, 20, NA, NA, NA, NA, NA, NA, 40)),
row.names = c(NA, -10L),
class = c("tbl_df", "tbl", "data.frame"))
which are divided into two 'sections' 'A' and 'B'. From both sections, I would like to keep data which were at least one day 'valid' for year 2021. Then, I would like to sum A_value and B_value. What steps would you suggest? Note, I have more tahn 2 'sections' and each 'section' has more than one 'value'.
many thanks,
Jakub