I am trying to perform simple calculations of on sub-set of observations in time-series df. The data is in tidy format. I'm stuck on how to subset and do the calculations in tidy format. I could expand the df into wide format and create new variables, but this seems like a step backwards.
For example using the built in txhousing data, I would like to calculate the sum of median house prices of Abilene and Amarillo (sum_median_aa) for each year/month combination. Once that variable is calculated, I would like to subtract it from Arlington median house price for each year/month combination (change= Arlington-sum_median_aa).
Sorry if it's a basic question. I'm still a "newbie" to Tidyverse and R.
df <- txhousing %>%
mutate(sum_median_aa = city$Abiline + city$Amarillo,
change = city$Arlington - sum_median_aa)