I am trying to create a table as shown in picture for multi response data with list of banner . i have tried the below way but didn't worked.
trying to replicate the output of spss in R . i am trying to create a function for this but unable to. any idea what i am doing wrong here ..??
library(expss)
data(mtcars)
mtcars1 <- mtcars
mtcars1$dd <- ifelse(mtcars1$gear == 4,1,NA)
mtcars1$ff <- ifelse(mtcars1$gear == 5,1,NA)
mtcars1$vs<-factor(mtcars1$vs, levels=c(0,1), labels=c("Male","female"))
mtcars1$am<-factor(mtcars1$am, levels=c(0,1), labels=c("Male","female"))
val_lab(mtcars1$dd)<-c("Local"=1)
val_lab(mtcars1$ff)<-c("Regional"=1)
mk <- with(mtcars1,list(total(),dd, ff))
#func1 <- function(dataset,vars,vars_name,Banner){
T1 <- mtcars1 %>%
tab_cells(mrset(vs %to% am)) %>%
tab_cols(mk) %>%
tab_stat_cpct() %>%
tab_pivot() %>%
split_table_to_df()
T1
#}
debugonce(func1)
tabl <- func1(dataset=data,vars=c("vs","am"),vars_name =c("ab","cd"),Banner=mk)
The output is am getting is
but the required output should be like