I always get this error: Error in Math.factor(c(1L, 3L, 4L, : 'round' not meaningful for factors for the following code:
C1<-train_data[,m]
C2<-as.factor(C1)
class_values<-C2
train_data <- train_data[,-m]
control <- trainControl(method="repeatedcv", number=5, repeats=1)
train_model <-train(train_data,class_values,method='nb',trControl=control)
I tried to put: C2=as.factor(as.numeric(as.character(C1)), but not solved. C1 is numeric data from 1 to 5.
For rounding: you should either do:
df <- data.frame(a = factor(c(1.1,2.2,3.3)))
df$b = round(as.numeric(levels(df$a)[df$a]))
Or using data.table framework:
require(data.table)
setDT(df)
df[, b:= round(as.numeric(levels(a)[a]))]
After, we would need to see what is in your functions to know what's wrong... Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.