creating function for expss tables

I am trying to create a function which can show tables like SPSS from EXPSS package.
i have database with variables having multiple factors and i want to show the percentage of responses for the variables but unable to create table.

library(expss)
df <- mtcars

df$all<- 1
df$small<-ifelse(df$vs==1,1,NA)
df$large<-ifelse(df$am ==1,1,NA)

val_lab(df$all)<-c("Total"=1)
val_lab(df$small)<-c("Small"=1)
val_lab(df$large)<-c("Large"=1)

banner <- list(df$all,df$small,df$large)

df$vs<-factor(df$vs, levels=c(0,1), labels = c("Available","Not AVailable"))
df$am<-factor(df$am, levels=c(0,1), labels = c("Available","Not AVailable"))


fun1 <- function(data,var_list,banner1){
  
  df1<-data[var_list] %>% as.data.frame() 
  
  t2 <-  df1 %>% 
    cross_cpct(
      cell_vars = var_list,
      col_vars = banner1
    )
  
  
}


fun1(data = df,var_list = c("vs","am"),banner1 = banner)

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.