I am a novice at R programming and stuck with a problem.
Here's a sample dataset:
df <- data.frame(
area_id = c(31,34,36,33,28,35, 31,34,36,33,28,35),
description = c('paramount','sony','star','miramax','pixar','zee', 'paramount','sony','star','miramax','pixar','zee'),
footfall = c(200, 354, 543, 123, 456, 634, 356, 765, 345, 235, 657, 524),
income = c(21000, 19000, 35000, 18000, 12000, 190000, 21000, 19000, 35000, 18000, 12000, 190000),
year = c(2019, 2019, 2019, 2019, 2019, 2019, 2020, 2020, 2020, 2020, 2020, 2020));
Now, I have two requirements:
Adding a column named "region" with values based on "area_id";
So, areas with "area_id" = 28, 34, 36 should have value as "West" in "region" column.
Similarly, areas with "area_id" = 31, 33, 35 should have value as "East" in "region" column.
Finally, I want a summary table stratified by year and aggregated region-wise. The final table should look like below:
Can anyone please help me out?