Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hos can I add a column porcentaje based on other column in my data frame?

I would like to create a column in my data frame that gives the percentage of each category. The total (100%) would be the summary of the column Score.

My data looks like

Client  Score
  <chr> <int>
1 RP      125
2 DM      30

Expected

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Client  Score    %
  <chr> <int>
1 RP      125    80.6
2 DM      30     19.3

Thanks!

>Solution :

Note special character in column names is not good.

library(dplyr)
df %>% 
  mutate(`%` = round(Score/sum(Score, na.rm = TRUE)*100, 1))
  Client Score    %
1     RP   125 80.6
2     DM    30 19.4
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading