when I was trying to use following code to pivot a group of variables which are named with a pattern:
Loop through variables
tables <- list()
pattern <- "aa_bb_cc"
for (i in c(1:6)) {
varname <-paste0(pattern,i)
caption <- attributes(df)$variable.labels[varname]
# Create table for current variable
table <- df %>%
tab_cells(get(varname)) %>%
tab_total_row_position(total_row_position = "none") %>%
tab_cols(total(),s_Sex) %>%
# tab_stat_cases() %>%
tab_stat_cpct() %>%
tab_pivot()%>%
tab_caption(caption)
tables[[i]] <- table
}
I got a table which has row lable as a combination of:
tables[[1]]$row_labels
[1] "get(varname)|Trifft voll und ganz zu" "get(varname)|Trifft eher zu"
[3] "get(varname)|Weder - noch" "get(varname)|Trifft eher nicht zu"
[5] "get(varname)|Trifft überhaupt nicht zu"
I would like to keep the only orginal levels from the data, is there a way in tab_* to turn off this paste setting ??
was trying to use some commands like :
var_lab, tab_row_label
dont work in this case
any hints are appreciated!