Hi everyone,
I just started to learn R and I'm having an issue. I have a data frame, a very simple one, of three columns of factor and integers.
library(tidyverse)
head(df,5)
#>
#> 1 function (x, df1, df2, ncp, log = FALSE)
#> 2 {
#> 3 if (missing(ncp))
#> 4 .Call(C_df, x, df1, df2, log)
#> 5 else .Call(C_dnf, x, df1, df2, ncp, log)
data.frame(
age = c(10L, 11L, 12L, 13L, 14L),
suicides = c(0L, 0L, 2L, 2L, 1L),
year = as.factor(c("1981", "1981", "1981", "1981", "1981"))
)
#> age suicides year
#> 1 10 0 1981
#> 2 11 0 1981
#> 3 12 2 1981
#> 4 13 2 1981
#> 5 14 1 1981
Created on 2020-05-02 by the reprex package (v0.3.0)
I would like to create a new dataframe where the columns "year" still remain the same, the columns "age" would show an interval like "10-19", "20-29" and so on, and the columns "suicides" would show the cumulative sum of values ranging from age 10 to age 19 then from age 20 to age 29 and so on.
Keep in mind that year span from 1981 to 2017 and age from 10 to 89 for all the year variable.
I think maybe it's an easy task but I didn' t find anything for now on internet.
I hope I've been clear enough explaining my issue and thanks in advance for your help!