title: Error in sample.int(m, k) : cannot take a sample larger than the population
body: <p>First, let me say that I'm fairly new to Machine Learning, kmeans, and r, and this project is a means to learn more about this and also to present this data to our CIO so I can use it in the development of a new help desk system.</p>
  <p>I have a 60K line text file. The file contains the titles of help desk tickets entered in by teachers over a 3 year period.</p>
  <p>I would like create a r program that takes these titles and creates a set of categories. For instance, terms related to printing issues, or a group of terms related to projector bulbs. I have used r to open the text document, clean up the data, remove stop words and other words that I felt were not necessary. I've gotten a list of all the terms with a frequency &gt;= 400 and saved those to a text file.</p>
  <p>But now I want to apply (if it can be done or is appropriate) kmeans clustering to that same data set and see if I can come up with categories.</p>
  <p>The code below includes code that will write out the list of terms used &gt;= 400. It is at the end, and is commented out.</p>
  <pre><code>library(tm) #load text mining library
  library(SnowballC)
  options(max.print=5.5E5) 
  setwd('c:/temp/') #sets R's working directory to near where my files are
  ae.corpus&lt;-Corpus(DirSource(&quot;c:/temp/&quot;),readerControl=list(reader=readPlain))
  summary(ae.corpus) #check what went in
  ae.corpus &lt;- tm_map(ae.corpus, tolower)
  ae.corpus &lt;- tm_map(ae.corpus, removePunctuation)
  ae.corpus &lt;- tm_map(ae.corpus, removeNumbers)
  ae.corpus &lt;- tm_map(ae.corpus, stemDocument, language = &quot;english&quot;)  
  myStopwords &lt;- c(stopwords('english'), &lt;a very long list of other words&gt;)
  ae.corpus &lt;- tm_map(ae.corpus, removeWords, myStopwords) 
  
  ae.corpus &lt;- tm_map(ae.corpus, PlainTextDocument)
  
  ae.tdm &lt;- DocumentTermMatrix(ae.corpus, control = list(minWordLength = 5))
  
  
  dtm.weight &lt;- weightTfIdf(ae.tdm)
  
  m &lt;- as.matrix(dtm.weight)
  rownames(m) &lt;- 1:nrow(m)
  
  #euclidian 
  norm_eucl &lt;- function(m) {
    m/apply(m,1,function(x) sum(x^2)^.5)
  }
  m_norm &lt;- norm_eucl(m)
  
  results &lt;- kmeans(m_norm,25)
  
  #list clusters
  
  clusters &lt;- 1:25
  for (i in clusters){
    cat(&quot;Cluster &quot;,i,&quot;:&quot;,findFreqTerms(dtm.weight[results$cluster==i],400,&quot;\n\n&quot;))
  }
  
  
  #inspect(ae.tdm)
  #fft &lt;- findFreqTerms(ae.tdm, lowfreq=400)
  
  #write(fft, file = &quot;dataTitles.txt&quot;,
  #      ncolumns = 1,
  #      append = FALSE, sep = &quot; &quot;)
  
  #str(fft)
  
  #inspect(fft)
  </code></pre>
  <p>When I run this using RStudio, I get:</p>
  <pre><code>&gt; results &lt;- kmeans(m_norm,25)
  </code></pre>
  <blockquote>
  <p>Error in sample.int(m, k) : cannot take a sample larger than the population when 'replace = FALSE'</p>
  </blockquote>
  <p>I'm not really sure what this means, and I haven't found a lot of info about this online. Any thoughts?</p>
  <p>TIA</p>