I have a large dataset and I want to apply comparegroups function in R. The dataset has number of grouping variables that I want to compare other variables on it; I wanted to loop over these grouping variables. the function is not accepting the loop
`vars <- c("fibrosis_stage", "Steatosis_stage", "patient_classification")
for (var in vars){
model <- compareGroups(var~.,data = data)
result.model <- createTable(model)
export2xls(result.model,paste0(var,"comparisons.xlsx"))
}`
but I got the following error: Error in model.frame.default(formula = var ~ ., data = list(Gender = c(2L, : variable lengths differ
I tried even to make it in a function; with the grouping varaible as input but I had an error also.
Any one can help?