Cumulative percentage of the column in R can be accomplished by using cumsum and sum function. In this tutorial we will see how to
- Get cumulative percentage of the column in R
Let’s first create the dataframe
df1 = data.frame(State = c('Arizona AZ','Georgia GG', 'Newyork NY','Indiana IN','Florida FL'), Score=c(62,47,55,74,31)) df1
df1 will be
Get cumulative percentage of column in R:
Cumulative percentage of a column is calculated using cumsum() and sum() function as shown below
# cumulative percentage df1$cumulative_percentage= 100*cumsum(df1$Score)/sum(df1$Score) df1
resultant dataframe will be,