title: How can I treat a "empty cluster" warning, in K-means function?
body: <p>I'm searching for a solution to treat a warning message, from the <code>Kmeans</code> function of <code>amap</code> package. The warning message is the following:</p>
  
  <p><code>empty cluster: try a better set of initial centers</code>. </p>
  
  <p>Is there anyway I could get a signal, so could know when this error message thrown, and then handle the problem? (e.g: running the algorithm until the there is the return has no empty cluster)</p>
  
  <p>It is quite hard to make a nice reproducible example for me. But, I came with this ugly, but functional:</p>
  
  <pre><code>library(amap)
  
  numberK = 20
  ts.len = 7
  
  time.series &lt;- rep(sample(1:8000, numberK, replace = TRUE),ts.len)
  time.series &lt;- rep(rbind(time.series, time.series), 30)
  time.series &lt;- matrix(time.series, ncol = ts.len)
  
  centers &lt;- matrix( sample(1:3000, numberK*ts.len), ncol = ts.len)
  
  Kmeans((time.series), centers = centers, iter.max = 99)
  </code></pre>
  
  <p>If you run this on you terminal, it might send you the warning message I'm talking about.</p>
  
  <p><strong>Note:</strong> <em>My thoughts of solving this problem is catching the signal of the warning, and then execute the solution. However, I have no idea how can I possibly do that</em></p>