tab_stat_cpct not giving the required result

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
image

but the required output should be like
image

If you want formatted tables with merged headers etc, then select an appropriate package that can translate a data.frame to a visual format, my choice would be package gt

actually i am replicating the spss output in R , thats why my dependency is on expss

Im urging you to distinguish between objects that serve storage/calculation purposes (i.e. dataframes) versus final reporting pretty prjnted outputs (html table).
What is your goal ?

the goal is to create spss like functions and get all the output spss like tables in excel. everything is done but now the only objective is to create this function to get this desired result

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.