https://i.stack.imgur.com/HiUcL.png
I have this data frame, and I want to calculate the sum of each year in UK column. Each year has 12 data points for each month.
How do I calculate the total value for each year in the dataframe?
https://i.stack.imgur.com/HiUcL.png
I have this data frame, and I want to calculate the sum of each year in UK column. Each year has 12 data points for each month.
How do I calculate the total value for each year in the dataframe?
You can use sqldf
for sum.
Assuming data frame name is df
install.packages(sqldf)
library(sqldf)
data <- sqldf("select year,month,
round(sum(UK),1) as Sum_UK,
from df
group by year,month")
Hope this will help,there are many other option also you can try like dplyr