0
df<- apply(temp2, 2, table)

I used this code and it only shows frequency. What can I add to this code to calculate percentage? temp2 has Gender(Male, Female), Age, location, Income & Investment. All of these are catagorical variables coded as 1, 2, 3 ,4, 5 except for Gender.

  • Please provide a sample of `temp2`, the best would be `dput(temp2)` or `dput(head(temp2,10))` if it is rather larger. – r2evans Jun 12 '23 at 00:20
  • 1
    How is gender coded? 1/0? 1/2? M/F? Male/Female? It would be really helpful if you followed [the guidelines](https://stackoverflow.com/help/how-to-ask) of asking a question and edited the question to [make it reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?noredirect=1&lq=1). – jpsmith Jun 12 '23 at 00:33
  • 1
    Try `apply(temp2, 2, \(x) prop.table(table(x)))` and multiply the results by 100 to get percentages. – Rui Barradas Jun 12 '23 at 04:03

0 Answers0