在R中为LaTeX创建多级表

时间:2016-10-28 16:40:07

标签: r latex xtable

我有一个因子调查数据,如:

> 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
...

我的目标是输出一个看似如下的LaTeX表:

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

我知道prop.table(table(d$colname))会为我提供每列所需的信息,但我无法弄清楚如何将结果格式化为一个表

0 个答案:

没有答案