R Kmeans and 'for' loop
22:15 02 Nov 2017

I am trying out this code, but somehow it isn't working.

   wss = NULL
   bss = NULL
   s_kmeans <- function(fname)
     {
       dataset <- read.csv(file=fname,header = TRUE, sep = ",")
       for(i in 1:10)
          {
            results <- kmeans(dataset,i)
            wss[i] <- results$tot.withinss
            bss[i] <- results$betweenss
          }
     }

I am trying to take two arrays, wss and bss. Run kmeans multiple times using a for loop and in each loop store values to total withinss and betweenss in wss and bss, respectively.

But when I run the code, I only get NULL stored in wss and bss. Is there a better way to do this?

arrays r for-loop