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