我试图根据它在数据框中因子列的值范围内的位置来获取数字的级别。
library(bnlearn)
i <- iris
idata4 <- i[,c(1:4)] #only first four columns, which are continuous
diris <- discretize(idata4, method = "hartemink", breaks = 8, ibreaks = 9, idisc = "quantile")
levels(diris$Sepal.Length)
> [1] "[4.3,4.9]" "(4.9,5.1]" "(5.1,5.4]" "(5.4,5.7]" "(5.7,5.98]" "(5.98,6.3]" "(6.3,6.84]" "(6.84,7.9]"
我正在尝试根据新值获取因子标签。给定一个值 5.5,有没有办法获取标签?
"(5.4,5.7]"
所以我可以将它分配给一个变量?像这样的东西?
newVariable <- function(5.5, diris$Sepal.Length)