1

Hello Im trying to run som and kmeans analysis. But I can't solve it because there's an error code. Error in storage.mode(x) <- "double" : 'list' object cannot be coerced to type 'double'

How can I solve this problem?

cdata <- read.delim("Cluster.txt", stringsAsFactors=FALSE)
cdata.n <- scale(subset(cdata, select=-c(ID)))
som_model2 <- supersom(data = cdata.n, grid = somgrid(10, 10, "rectangular"))
k = 6
somClusters <- kmeans(som_model2$codes, centers = 6)

I want to culstering into 6 clusters. Please help me

I use this data. https://github.com/woosa7/R_DataAnalytics/blob/08ea98289f4def3c4f72d4c10d3767784b42619b/R_DataMining/data/Cluster.txt

Sunghee
  • 17
  • 2

1 Answers1

0

Try unlist:

somClusters <- kmeans(unlist(som_model2$codes), centers = 6)
somClusters
Cluster means:
        [,1]
1 -0.6702128
2  5.2157179
3  1.2555768
4 -0.2632253
5  2.6067733
6  0.3503127

Clustering vector:
  [1] 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6 6 4 4 4 4 4 4 4
 [50] 4 6 6 4 6 4 4 4 4 4 4 6 3 3 6 6 4 4 4 4 4 3 3 3 3 6 6 4 4 4 4 5 5 3 3 6 6 4 4 4 4 2 5 3 6 6 6 4 6
 [99] 6 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 4 1 1 1 1 1 1 4 1 1 1 1 1 6 6 4 4 4 4 1 4 1 1 3 3 6 6 4 4 4
[148] 1 4 4 3 3 6 6 6 4 4 4 4 4 5 5 3 6 4 6 4 4 4 4 5 5 3 6 6 6 6 6 4 4 2 5 3 3 6 6 6 6 4 4 2 5 3 6 3 6
[197] 6 6 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 1 1 4 4 4 4 4 3 3 4 4 4
[246] 4 4 4 4 4 3 3 6 4 6 4 6 6 4 4 3 3 6 6 6 6 6 6 6 6 5 3 3 3 3 6 6 6 6 6 5 5 3 3 3 3 3 6 6 6 5 5 5 5
[295] 3 3 3 3 3 6 2 5 3 3 6 6 4 4 4 1 5 5 3 3 6 6 6 4 4 1 5 3 3 6 6 6 4 4 4 1 3 6 6 6 4 6 6 4 4 1 1 1 4
[344] 4 4 4 6 4 4 1 1 1 1 1 4 4 4 4 4 1 1 1 1 1 1 1 4 4 4 1 1 1 1 1 1 1 4 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1
[393] 1 1 1 1 1 1 1 4

Within cluster sum of squares by cluster:
[1] 1.939971 9.714721 4.939015 2.981251 3.051715 3.374086
 (between_SS / total_SS =  93.6 %)

Available components:

[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss" "betweenss"   
[7] "size"         "iter"         "ifault"  
TarJae
  • 72,363
  • 6
  • 19
  • 66
  • Thank you:) Let me ask you one more question. In the example file above, the results came out as follows. What should I do to get this result? ## Cluster means: ## MONEY VISIT CROSS API ## 1 8.2237320 4.8942046 3.6120212 -0.8606384 ## 2 -0.2699493 -0.3223770 -0.3357094 -0.2496793 ## 3 0.3566740 0.5408914 0.9180064 -0.6252556 ## 4 -0.4596952 -0.6586599 -0.9624127 4.2828612 ## 5 2.0625665 2.6264913 2.0452184 -0.7848548 ## 6 -0.4199132 -0.5746073 -0.7785007 1.1355674 – Sunghee Dec 11 '21 at 08:56