I called Convert the column format data.frame from character to coefficient and Convert multiple columns of data.table to factors in R and Convert column classes to data.table
Unfortunately, this did not solve my problem. I am working with a bodyfat dataset and my dataframe is called> bf. I added an agegrp column to classify people of different ages as young, middle, or old, this way:
bf$agegrp<-ifelse(bf$age<=40, "young", ifelse(bf$age>40 & bf$age<55,"middle", "old"))
This is ctree analysis:
> set.seed(1234)
> modelsample<-sample(2, nrow(bf), replace=TRUE, prob=c(0.7, 0.3))
> traindata<-bf[modelsample==1, ]
> testdata<-bf[modelsample==2, ]
> predictor<-agegrp~DEXfat+waistcirc+hipcirc+kneebreadth` and ran, `bf_ctree<-ctree(predictor, data=traindata)
> bf_ctree<-ctree(predictor, data=traindata)
I got the following error:
Error in trafo(data = data, numeric_trafo = numeric_trafo, factor_trafo = factor_trafo, :
data class character is not supported
In addition: Warning message:
In storage.mode(RET@predict_trafo) <- "double" : NAs introduced by coercion
Since it bf$agegrphas a character class, I ran,
> bf$agegrp<-as.factor(bf$agegrp)
the agegrp column is now coerced to factor.
> Class (bf$agegrp)gives [1] "Factor".
ctree, . - , ?