Crosstab with multiple items

前端 未结 7 987
天命终不由人
天命终不由人 2021-02-01 10:48

In SPSS, it is (relatively) easy to create a cross tab with multiple variables using the factors (or values) as the table heading. So, something like the following (made up dat

7条回答
  •  难免孤独
    2021-02-01 10:59

    Modifying a previous example

    library(Hmisc)
    library(plyr)
    dd <- data.frame(q1=sample(1:3, 20, replace=T),
     q2=sample(1:3, 20, replace=T), 
     q3=sample(1:3, 20, replace=T))  #fake data
    
    cross <- ldply(describe(dd), function(x) x$values[1,])[-1]
    
    rownames(cross) <- c("Q1. Likes it","Q2. Recommends it","Q3. Used it")
    names(cross) <- c("1 (very Often)","2 (Rarely)","3 (Never)")
    

    Now cross looks like this

    > cross
                      1 (very Often) 2 (Rarely) 3 (Never)
    Q1. Likes it                   4         10         6
    Q2. Recommends it              7          9         4
    Q3. Used it                    6          4        10
    

提交回复
热议问题