Previously today I posted this question here but I have an additional question that has been raised.
If I had to more variables in original data frame (loc, height):
var = c(rep("A",3),rep("B",2),rep("C",5));var
date = c(as.Date("2022/01/01"),as.Date("2022/02/01"),as.Date("2022/03/01"),
as.Date("2022/01/01"),as.Date("2022/03/01"),
as.Date("2022/01/01"),as.Date("2022/01/01"),as.Date("2022/02/01"),as.Date("2022/02/01"),as.Date("2022/03/01"))
loc = c(rep("london",3),rep("berlin",2),rep("cairo",5))
height =c(13,14,15,13,15,16,12,14,13,15)
data = tibble(var,date,loc,height);data
how can I keep the corresponding values of the loc variable and the total (sum) of height in each month (in addition in the previously answered question) ?
Ideally it must look now like this :
| var | Quarter | Month | Condition | loc | height |
|---|---|---|---|---|---|
| A | 1 | 1 | TRUE | London | 13 |
| A | 1 | 2 | TRUE | London | 14 |
| A | 1 | 3 | TRUE | London | 15 |
| B | 1 | 1 | TRUE | berlin | 13 |
| B | 1 | 2 | FALSE | berlin | 0 |
| B | 1 | 3 | TRUE | berlin | 15 |
| C | 1 | 1 | TRUE | cairo | 28 |
| C | 1 | 2 | TRUE | cairo | 27 |
| C | 1 | 3 | TRUE | cairo | 15 |
any help ? how I do it in R using dplyr ?