I have some Electric Vehicle charging capacity projections from 2019 to 2050 for different areas and charger types. I want to sum the values across the total area and group by charger type like so:
df %>%
group_by(ChargerType) %>%
summarise(sum2019 = sum(df$`2019`))
But I want to do it for all years from 2019 to 2050. This can be done individually but would be very tedious and I'm sure there is a nice way to do it all in one!
Example data for you to try can look like this:
Area <- c(1,1,1,2,2,2,3,3,3)
ChargerType <- c("Domestic", "Public", "Fast", "Domestic", "Public", "Fast", "Domestic", "Public", "Fast")
`2019` <- c(0.1,0,0.3,0.5,0.1,0.2,0,0,0.1)
`2020` <- c(0.2,0.2,0.4,0.6,0.2,0.2,0.1,0,0.2)
`2021` <-c(0.4,0.3,0.4,0.8,0.3,0.2,0.2,0.2,0.3)
df <- data.table(Area, ChargerType, `2019`, `2020`, `2021`)
This is small example to help you, obviously for only up until 2021 but feel free to create more data!
Hope you can help, sure it would be easy for someone out there!