use tidyverse

If I understood you correctly

library(FNN)
library(tidyverse)
Kmeans.list <- map(.x = mylist,
                   .f = ~kmeans(scale(.x[,-c(1:2)]),
                                centers =15,
                                nstart=50,
                                iter.max = 100)) %>% 
                    purrr::set_names(c("df1", "df2"))

Kmeans_centers <- map(Kmeans.list, ~.x$centers)


n500 <- map2(
  .x = mylist,
  .y = Kmeans_centers,
  .f = ~ get.knnx(data = scale(.x[, -c(1:2)]), query = .y, k = 500)) %>% 
  purrr::set_names(c("df1", "df2"))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top