I am using the dataframe "death rates in Virginia" for a class project. I need to normalize the data so that they can be compared and analyzed. Is there a way for me to take each row and calculate the percentage of each value from each row instead of doing it manually? for example if I have a row of 1, 2, 3, 4, 5: I would like to sum do the following to each individual object in the row: x/sum of all objects * 100. is there a quick way to do this to each row? Thanks
Asked
Active
Viewed 166 times
-1
-
2Have you used `prop.table`? try `prop.table(1:5)` in your console – AnilGoyal May 25 '21 at 07:49
-
take a look at the percentagaes-functions from the `janitor`-package – Wimpel May 25 '21 at 08:01
1 Answers
0
with base functions
dummy_df <- data.frame(a=sample(1:100,20),b=sample(1:100,20),c=sample(1:100,20))
t(apply(dummy_df,1,function(x) {100*(x/sum(x))}))

Samet Sökel
- 2,515
- 6
- 21