【问题标题】:R error using DBSCAN on Data frame在数据帧上使用 DBSCAN 出现 R 错误
【发布时间】:2016-08-09 09:11:32
【问题描述】:

数据错误 - x : 二元运算符的非数字参数
我的代码如下:

x <- as.factor(c(2, 2, 8, 5, 7, 6, 1, 4))

y <- as.factor(c(10, 5, 4, 8, 5, 4, 2, 9))

coordinates <- data.frame(x, y)

colnames(coordinates) <- c("x_coordinate", "y_coordinate")

print(coordinates)

point_clusters <- dbscan(coordinates, 2, MinPts = 2, scale = FALSE,
    method = c("hybrid", "raw", "dist"), seeds = TRUE, 
    showplot = 1, countmode = NULL)

point_clusters

但在执行上述代码时出现以下错误:

> point_clusters <- dbscan(coordinates, 2, MinPts = 2, scale = FALSE, method = c("hybrid", "r ..." ... [TRUNCATED] 
Error in data - x : non-numeric argument to binary operator

我不知道上面的代码有什么问题。

【问题讨论】:

    标签: r dataframe cluster-analysis dbscan


    【解决方案1】:

    我根据需要解决了问题。我在某处看到 data 需要是 numeric matrix,但我不确定。所以,这就是我所做的:

    x <- c(2, 2, 8, 5, 7, 6, 1, 4)
    y <- c(10, 5, 4, 8, 5, 4, 2, 9)
    coordinates <- matrix(c(x, y), nrow = 8, byrow = FALSE)
    

    其余代码同上。现在它对我来说很好用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 2011-07-30
      • 2019-01-28
      • 2017-07-21
      • 2018-09-22
      • 1970-01-01
      相关资源
      最近更新 更多