Hi I am trying to create a function for EXPSS table, sample data below
dput( dataa<-data.frame(
aa = c("q","r","y","v","g","y","d","s","n","k","y","d","s","t","n","u","l","h","x","c","q","r","y","v","g","y","d","s","n","k","y","d","s","t","n","u","l","h","x","c"),
col1=c(1,2,3,2,1,2,3,4,4,4,5,3,4,2,1,2,5,3,2,1,2,4,2,1,3,2,1,2,3,1,2,3,4,4,4,1,2,5,3,5),
col2=c(2,1,1,7,4,1,2,7,5,7,2,6,2,2,6,3,4,3,2,5,7,5,6,4,4,6,5,6,4,1,7,7,2,7,7,2,3,7,2,4)
)
)
function i created is
crosstab_sum <- function(dat1,var1,var2)
{
var1 <- rlang::parse_expr(var1)
var2 <- rlang::parse_expr(var2)
dat1 = dat1 %>% select(!!var1,!!var2)
expss::var_lab(dat1[[1]]) <- ""
expss::var_lab(dat1[[2]]) <- ""
tab1 <- expss::cro_cpct(dat1[[1]],dat1[[2]])
tab1 <- as.data.frame(tab1)
tab1[is.na(tab1)] <- 0
tab1 <- tab1 %>% mutate_if(is.numeric,round,digits=1)
tab1 <- flextable:: flextable(tab1)
tab1
}
now i want to add a criteria in this function on total but unable to explore how i can apply the below criteria (max_m) in my above function.
max_n<-c(3,4,5)
max_m<-function(x,N){
x= ifelse(N<max_n[1],"--",x)
}
in this function "N" is total number of occurence
also do we have any solution to concatenate "%" in all values except Total