-1

This is an image of my dataset now.

I would like to create a new column that holds percentages based on Dialect and Age Group. For example, the percentage for Cantonese aged 0-19 should be [72709 / (72709 + 112149 + 133188 + 70825)] *100 = 18.697%. I would appreciate any help with this problem.

1 Answers1

0

Please add some data in the form of a dput() output, but I think this should do it

library(dplyr)
data %>%
  group_by(Dialect) %>%
  mutate(percent = value /sum(value) * 100)
L Smeets
  • 888
  • 4
  • 17