3

I have a factor survey data like:

> sex <- sample(c('M','F'), 10, replace=T)
> income <- sample(c('< 10,000','10,000-50,000','> 50,000'), 10, replace=T)
> location <- sample(c('Chicago','New York','Los Angeles'), 10, replace=T)
> 
> d <- data.frame(cbind(sex, income, location))
> d
   sex        income    location
1    M 10,000-50,000    New York
2    M      > 50,000    New York
3    M 10,000-50,000     Chicago
4    F      < 10,000     Chicago
5    M      > 50,000 Los Angeles
6    F      > 50,000 Los Angeles
7    F      < 10,000    New York
8    F      > 50,000 Los Angeles
9    F 10,000-50,000    New York
10   F      < 10,000 Los Angeles
...

My goal is to output a LaTeX table that looks like:

Sex                 Percent
    M               50
    F               50
Income
    < 10,000        25
    10,000-50,000   50
    > 50,000        25
...

I know that prop.table(table(d$colname)) will get me the info that I want for each column, but I can't figure out how to get the result formatted all in one table

Jeremy
  • 1,960
  • 4
  • 21
  • 42

0 Answers0