R中的聚类分离

时间:2016-06-09 10:41:37

标签: r cluster-analysis

集群已经形成。现在,我想知道我们是否可以从特定的群集ID中选择元素。 以下是形成的不同群集。

  1    2    3    4    5    6    7    8    9 
 549  290 1206  103   97  102    2  208  123

  10   11   12   13   14   15   16   17   18 
  17   75  293  981   23  586   25   15  365 

就像,我必须从群集12中选择元素。然后,如何做到

这是用于形成集群的代码:

db <- dbscan(cbind(Final$event_begin_longitude,Final$event_begin_latitude), .0025, minPts = 1, scale = FALSE, method = "raw")

1 个答案:

答案 0 :(得分:0)

没有预定义的方法来访问群集的元素。但是,您可以轻松地自己完成。 dbscan的返回值有一个名为clusters的插槽,其输入顺序与输入的顺序相同:

dta <- structure(list(V1 = c(0, 0.04, 0.09, 0.13, 0.17, 0.22, 0.26, 0.3, 0.35, 0.39, 0.43, 0.48, 0.52, 0.57, 0.61, 0.65, 0.7, 0.74, 0.78, 0.83, 0.87, 0.91, 0.96, 1), 
                  V2 = c(0.01, 0.01, 0, 0, 0.08, 0.03, 0.01, 0.05, 0.45, 0.73, 0.91, 0.9, 0.67, 0.77, 0.98, 0.94, 0.86, 1, 0.38, 0.09, 0.01, 0.01, 0, 0)), 
             .Names = c("V1", "V2"), 
             row.names = c(NA, -24L), 
             class = "data.frame")

db <- dbscan::dbscan(dta, .25, minPts = 1)

# Combine values and their cluster
cbind(dta, db$cluster)

# Plot with colored clusters
plot(dta, col = db$cluster, pch = 16)

DBSCAN cluster color coded plot

相关问题