Percentage of the column in R is calculated in roundabout way using sum function. Let’s see how to calculate
- Percentage of the column in R with example
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
So the resultant dataframe will be
Percentage of the column in R:
Percentage of the column is calculated in roundabout way using sum function as shown below
df1$score_percen= 100*(df1$Score/sum(df1$Score)) df1
so the resultant dataframe will be