variance_homo<-function(df,col1,col2){
if (is.numeric(df[,col2]) & nlevels(df[,col1])>2){
bartlett_res<-bartlett.test(col2~col1,df,na.action=na.omit)
leven_res<-leveneTest(col2,col1,data=df,na.action=na.omit)
}
return(bartlett_res)
}
Above script is a simple function,when I run it ,got error as below:
> variance_homo(iris,'Species','Sepal.Length')
Error in bartlett.test.default("Sepal.Length", "Species") :
all observations are in the same group
Called from: bartlett.test.default("Sepal.Length", "Species")
Wha's the problem??