K均值聚类得出不同的数据集

时间:2020-10-24 06:08:44

标签: r cluster-analysis k-means

我组合了不同的数据集以进行K均值聚类。得到结果后,我想将结果一个接一个地应用到数据中。但是我不确定该怎么做,我们将不胜感激。

#Here is the result 
> VelocityClusters$centers
       [,1]
1 31.587619
2 75.769877
3 48.545961
4  5.252514

这是我编写的代码,试图将k-均值结果应用回单个数据集中,但是我知道这似乎不正确。 我一直在网上搜索,但似乎找不到答案。

m1_teamA<- m1_teamA %>%
  mutate(Phases = ifelse(mmin %in% 0:5.252514, "walk",
                         ifelse(mmin %in% 5.252515:31.587619,"Jog",
                                ifelse(mmin %in% 31.587620:48.545961, "Run","Sprint"))))


1 个答案:

答案 0 :(得分:0)

您可以使用cbind连接数据集中的新列数据

数据集名称<-cbind(数据集名称,VelocityClusters $ centers)

或者,您可以使用以下代码

最终<-data.frame(dataset_name,VelocityClusters $ centers)