I thought that this
kmeans(x = matrix(1:50, 5), centers = 2, iter.max = 10)
Could be written as:
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'
But the second does not work. How do I use kmeans in combination with purrr::map()?
maphere?matrix(1:50, 5) %>% kmeans(., centers = 2, iter.max = 10). Amatrixis avectorwith dim attributes. When you domap, it goes through each single observation. - akrunlist, thenmapcan be applied - akrunlisti.e.list(matrix(1:50, 5), matrix(51:100, 5)) %>% map( ~kmeans(x = .x, centers = 2, iter.max = 10))- akrun