-1

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

1 Answers1

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