We can convert those factor
columns to numeric
library(dplyr)
library(magrittr)
mydata %<>%
mutate_if(is.factor, funs(as.numeric(as.character(.))))
Or using base R
i1 <- sapply(mydata, is.factor)
mydata[i1] <- lapply(mydata[i1], function(x) as.numeric(as.character(x)))
and then the code should work
2
solved R: Not meaningful for factors even though its data type is numeric [duplicate]