1
kmeans(x = matrix(1:50, 5), centers = 2, iter.max = 10)
可以写成:
matrix(1:50, 5) %>%
map(~kmeans(x = .x, centers = 2, iter.max = 10))
Error in sample.int(m, k) :
cannot take a sample larger than the population when 'replace = FALSE'
但第二不起作用。我如何结合purrr::map()
使用kmeans
?
为什么你需要'map'在这里? '矩阵(1:50,5)%>%kmeans(。,center = 2,iter.max = 10)'。 “矩阵”是具有暗淡属性的“矢量”。当你做“地图”时,它会经历每一次观察。 – akrun
@akrun,因为在我的原始示例中,我有几个矩阵(缩放,带/不带某些变量等),我想比较彼此的聚类结果。 – Dambo
不知道我明白了。如果你在'list'中有几个矩阵,那么'map'可以应用 – akrun