Creates a table with columns for allowed values and rows for variables.

likert(data, vlist, columnlabels, valuelabels, rows = FALSE, digits = 2, ...)

Arguments

data

A data frame. Function will try to include all variables in data, unless vlist is provided.

vlist

A vector of column names in data that should be displayed

columnlabels

Column labels, optional to beautify variable names. If not supplied, column names will be used as column labels. Provide either 1) A named vector that replaces one or more columns, c(oldname1 = "newlabel1", oldname2 = "newlabel2") where oldnames are in colnames(data), or 2) a vector of same length as vlist (or data if vlist is not supplied) that will replace them one for one.

valuelabels

A vector of values to beautify existing levels. If not supplied, factor levels will be used as row labels

rows

Should output be transposed. This may help if there are many variables that need to fit on the page. Percentages will appear on the rows, rather than columns.

digits

Number of decimals to display in percentages

...

Arguments to pass to R's table function. We suggest useNA = "always" to add missing value information and exclude = original.value.label to exclude values observed. Currently, useNA = "ifany" does not work as expected, the number of missings will be displayed, even if there are none.

Value

A list, including a frequency table (called "freqTab"), column counts ("counts"), column sums ("sums"), and column percents ("pcts").

Author

Paul Johnson <pauljohn@ku.edu>

Examples

vvector <- c("Strongly Disagree", "Disagree", "Neutral",
              "Agree", "Strongly Agree")
set.seed(2342234)
N <- 28
scales <-
    data.frame(Vegas = factor(sample(1:5, N, replace = TRUE),
        levels = 1:5, labels = vvector),
               NewYork = factor(sample(1:5, N, replace = TRUE),
        levels = 1:5, labels = vvector),
               Paris = factor(sample(1:5, N, replace = TRUE),
        levels = 1:5, labels = vvector),
               Berlin = factor(sample(1:5, N, replace = TRUE),
        levels = 1:5, labels = vvector))

likert(scales)
#>                   Vegas        NewYork      Paris         Berlin      
#> Strongly Disagree "21.43% (6)" "32.14% (9)" "17.86% (5)"  "28.57% (8)"
#> Disagree          "17.86% (5)" "7.14% (2)"  "10.71% (3)"  "10.71% (3)"
#> Neutral           "17.86% (5)" "17.86% (5)" "35.71% (10)" "25.00% (7)"
#> Agree             "21.43% (6)" "14.29% (4)" "21.43% (6)"  "17.86% (5)"
#> Strongly Agree    "21.43% (6)" "28.57% (8)" "14.29% (4)"  "17.86% (5)"
#> Total             "28"         "28"         "28"          "28"        

likert(scales, exclude = "Disagree")
#>                   Vegas        NewYork      Paris         Berlin      
#> Strongly Disagree "26.09% (6)" "34.62% (9)" "20.00% (5)"  "32.00% (8)"
#> Neutral           "21.74% (5)" "19.23% (5)" "40.00% (10)" "28.00% (7)"
#> Agree             "26.09% (6)" "15.38% (4)" "24.00% (6)"  "20.00% (5)"
#> Strongly Agree    "26.09% (6)" "30.77% (8)" "16.00% (4)"  "20.00% (5)"
#> Total             "23"         "26"         "25"          "25"        

likert(scales, exclude = "Strongly Disagree", useNA = "ifany")
#>                Vegas        NewYork      Paris         Berlin      
#> Disagree       "22.73% (5)" "10.53% (2)" "13.04% (3)"  "15.00% (3)"
#> Neutral        "22.73% (5)" "26.32% (5)" "43.48% (10)" "35.00% (7)"
#> Agree          "27.27% (6)" "21.05% (4)" "26.09% (6)"  "25.00% (5)"
#> Strongly Agree "27.27% (6)" "42.11% (8)" "17.39% (4)"  "25.00% (5)"
#> NA             "0.00% (0)"  "0.00% (0)"  "0.00% (0)"   "0.00% (0)" 
#> Total          "22"         "19"         "23"          "20"        

(mySummary1 <- likert(data = scales, vlist = c("Vegas", "NewYork", "Paris")))
#>                   Vegas        NewYork      Paris        
#> Strongly Disagree "21.43% (6)" "32.14% (9)" "17.86% (5)" 
#> Disagree          "17.86% (5)" "7.14% (2)"  "10.71% (3)" 
#> Neutral           "17.86% (5)" "17.86% (5)" "35.71% (10)"
#> Agree             "21.43% (6)" "14.29% (4)" "21.43% (6)" 
#> Strongly Agree    "21.43% (6)" "28.57% (8)" "14.29% (4)" 
#> Total             "28"         "28"         "28"         
mySummary1[["pcts"]]
#>                      Vegas   NewYork    Paris
#> Strongly Disagree 21.42857 32.142857 17.85714
#> Disagree          17.85714  7.142857 10.71429
#> Neutral           17.85714 17.857143 35.71429
#> Agree             21.42857 14.285714 21.42857
#> Strongly Agree    21.42857 28.571429 14.28571

(mySummary2 <- likert(scales, vlist = c("Vegas", "NewYork", "Paris"),
                    valuelabels = c("SD", "D", "N", "A", "SA")))
#>       Vegas        NewYork      Paris        
#> SD    "21.43% (6)" "32.14% (9)" "17.86% (5)" 
#> D     "17.86% (5)" "7.14% (2)"  "10.71% (3)" 
#> N     "17.86% (5)" "17.86% (5)" "35.71% (10)"
#> A     "21.43% (6)" "14.29% (4)" "21.43% (6)" 
#> SA    "21.43% (6)" "28.57% (8)" "14.29% (4)" 
#> Total "28"         "28"         "28"         
(mySummary3 <- likert(scales, vlist = c("Vegas", "NewYork", "Paris"),
                    valuelabels = c("Strongly Disagree" = "Strong Disagreement")))
#>                     Vegas        NewYork      Paris        
#> Strong Disagreement "21.43% (6)" "32.14% (9)" "17.86% (5)" 
#> Disagree            "17.86% (5)" "7.14% (2)"  "10.71% (3)" 
#> Neutral             "17.86% (5)" "17.86% (5)" "35.71% (10)"
#> Agree               "21.43% (6)" "14.29% (4)" "21.43% (6)" 
#> Strongly Agree      "21.43% (6)" "28.57% (8)" "14.29% (4)" 
#> Total               "28"         "28"         "28"         

(mySummary5 <- likert(scales, vlist = c("Vegas", "NewYork", "Paris"),
      valuelabels = c("SD", "D", "N", "A", "SA"),
      columnlabels = c("Vegas" = "Sin City"), rows = TRUE))
#>          SD           D            N             A            SA          
#> Sin City "21.43% (6)" "17.86% (5)" "17.86% (5)"  "21.43% (6)" "21.43% (6)"
#> NewYork  "32.14% (9)" "7.14% (2)"  "17.86% (5)"  "14.29% (4)" "28.57% (8)"
#> Paris    "17.86% (5)" "10.71% (3)" "35.71% (10)" "21.43% (6)" "14.29% (4)"
#>          Total
#> Sin City "28" 
#> NewYork  "28" 
#> Paris    "28" 

 ## Example of how one might write this in a file. 
 ## print(xtable::xtable(mySummary1[[1]], digits = 1),
 ##       type = "html", file = "varCount-1.html")