Getting both column counts and proportions in the same table in R

后端 未结 3 1637
礼貌的吻别
礼貌的吻别 2020-12-14 13:19

If there a function that will give me both counts and column/overall percents in the same table? I can looked at both tables and reshape2 and don\'t see an option for doing

3条回答
  •  一向
    一向 (楼主)
    2020-12-14 13:49

    Here is one approach, you still need a second step, but it comes before the tabular command so the result is still a tabular object.

    n <- 100 
    x <- sample(letters[1:3], n, T) 
    y <- sample(letters[1:3], n, T) 
    d <- data.frame(x=x, y=y) 
    d$z <- 1/ave( rep(1,n), d$x, FUN=sum )
    
    (t1 <- tabular(x~y*Heading()*z*((n=length) + (p=sum)), d))
    

提交回复
热议问题