1

My datafram currently looks like this:

ID <- c(1, 2, 3, 4, 5, 6, 7)
Sex <- c(M, F, F, M, F, M, F)
Sector <- (Agri, Hospitality, Textiles, Agri, Manufacturing, Education, Agri)
Weights <- (1359.7148, 516.4853, 435.0078, 1722.3962,1481.6194, 1133.3163, 1558.3099)

Data <- data.frame(ID, Sex, Sector, Weights)

How should I go about calculating what the percentage of the population is in each Sector, by sex. I would also like to ask that when calculation percentages, should I sum Weights or should I sum over the number of observations I have.

Thank you very much.

anrisakaki96
  • 193
  • 8
  • Also your provided data isn‘t wirking. It‘s missing quotation marks around the character strings. Please update. And there are several other issues with your example data. So it would be better if you would provide an example with dput. – deschen Feb 17 '22 at 12:38

1 Answers1

0

Although there‘s currently no working example data, you might look for sth. like this:

library(tidyverse)
Data %>%
  group_by(Sex) %>%
  count(Sector, wt = Weights) %>%
  mutate(prop = n/sum(n))
deschen
  • 10,012
  • 3
  • 27
  • 50