I am facing this error even mydata is not null.How to overcome this error.
> dim(som_model$codes)
NULL
> som_model$codes
[[1]]
Monetray Frequency Recency
V1 -0.222667452 -0.3524154924 0.04209164
V2 -0.216275559 -0.3538082762 0.21107959
V3 -0.212684685 -0.3474491246 0.43714767
V4 -0.237204286 -0.3659989235 0.61105297
V5 -0.205093463 -0.3229735212 0.79368476
> mydata <- som_model$codes
> wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))
Error in apply(mydata, 2, var) : dim(X) must have a positive length
> length(mydata)
[1] 1
> mydata
[[1]]
Monetray Frequency Recency
V1 -0.222667452 -0.3524154924 0.04209164
V2 -0.216275559 -0.3538082762 0.21107959
https://www.r-bloggers.com/self-organising-maps-for-customer-segmentation-using-r/
som_model$codes
looks like a list with a matrix at index 1. You should be able to access the matrix by using:
mydata <- som_model$codes[[1]]
Instead of
mydata <- som_model$codes