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)
}
Вышеуказанный скрипт является простой функцией, когда я запускаю его, получаю ошибку, как показано ниже:
> 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")
В чем проблема ??