离散函数引发突发错误

时间:2019-11-06 12:56:18

标签: r

我正在使用R 3.6.1。我想离散化连续变量。我尝试使用https://www.rdocumentation.org/packages/arules/versions/1.6-4/topics/discretize中的离散化函数。但这会引发错误。

library(infotheo)
data(iris)
x <- iris[,1]
table(discretize(x, breaks = 3))
Error in discretize(x, breaks = 3) : unused argument (breaks = 3)

3 个答案:

答案 0 :(得分:1)

您加载到错误的程序包。您所指的功能来自arules

library(infotheo)
library(arules)

x <- iris[,1]
table(arules::discretize(x, breaks = 3)) #works
table(infotheo::discretize(x, breaks = 3)) # does not have a breaks argument

答案 1 :(得分:1)

您似乎正在使用infotheo::discretize,它没有breaks参数。这是文档给出的参数:

# library(infotheo)
discretize( X, disc="equalfreq", nbins=NROW(X)^(1/3) )

您链接到的包是arules,并且arules::discretize确实有一个breaks参数:

# library(arules)
discretize(x, method = "frequency", breaks = 3, 
  labels = NULL, include.lowest = TRUE, right = FALSE, dig.lab = 3,
  ordered_result = FALSE, infinity = FALSE, onlycuts = FALSE, 
  categories, ...)

答案 2 :(得分:1)

R中有很多库,您尝试使用 arules 包中的 discretize 函数。如果您同时加载了两个软件包:

library(infotheo)
library(arules)
data(iris)
x <- iris[,1]
table(arules::discretize(x, breaks = 3))

table(infotheo::discretize(x, nbins = 3))