NewBee
NewBee

Reputation: 1040

How to rename the labels that appear outside of the ctable output [summarytools]

I am trying to play around with the formatting of the labels in summarytools::ctable with no luck.

I would like to keep the longer version of the question name on top of the table, and the shorter version of the question name inside the table (or removed altogether).

Example of long var names
library(magrittr)
library(dplyr)
library(summarytools)

mtcars %<>% rename(really_long_variable_name_for_vs = vs, 
                   really_long_variable_name_for_gear = gear)
If I wanted xtabs of vs and gear with the the new longer names
ctable(mtcars$really_long_variable_name_for_gear,mtcars$really_long_variable_name_for_vs)
To specify shorter names I can use dnn
ctable(mtcars$really_long_variable_name_for_gear,mtcars$really_long_variable_name_for_vs,dnn = c('gear short', 'vs short'))

enter image description here


But I want the SHORT version of the name to appear inside the table (or not at all) And the LONG version of the var name to appear outside the table

Desired output:

enter image description here

I tried playing around with the options -- but no luck:

ctable(mtcars$gear,mtcars$really_long_variable_name_for_vs, 
       omit_headings = TRUE,
       display.labels = FALSE,
       dfSummary.labels.col = FALSE)

Upvotes: 0

Views: 102

Answers (1)

Dominic Comtois
Dominic Comtois

Reputation: 10401

In principle, you would use the print method to do that, modifying the Row.variable and Col.variable attributes. However, I realize it's not been correctly implemented. So what you can do is modify the Row.x.Col attribute directly (not documented):

ct <- ctable(...)
attr(ct, "data_info")$Row.x.Col <- "long_variable_name * other_long_variable_name"

Upvotes: 0

Related Questions