title: basic clustering with r
body: <p>I'm new to R and data analysis. I'm trying to create a simple custom recommendation system for a web site. So, as input information I have <code>user/session-id,item-id,item-price</code> which users clicked at. </p>
  
  <pre><code>c165c2ee-81cf-48cf-ba3f-83b70204c00c    161785  124.0
  a886fdd5-7cee-4152-b1b7-77a2702687b0    643339  42.0
  5e5fd670-b104-445b-a36d-b3798cd43279    131332  38.0
  888d736f-99bc-49ca-969d-057e7d4bb8d1    1032763 39.0
  </code></pre>
  
  <p>I would like to apply cluster analysis to that data.</p>
  
  <p>If I try to apply k-means clustering to my data:</p>
  
  <pre><code>&gt; q &lt;- kmeans(dat, centers=25)
  Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
  In addition: Warning message:
  In kmeans(dat, centers = 25) : NAs introduced by coercion
  </code></pre>
  
  <p>If I try to apply hierarchial clustering to the data:</p>
  
  <pre><code>&gt; m &lt;- as.matrix(dat)
  &gt; d &lt;- dist(m)   # find distance matrix
  Warning message:
  In dist(m) : NAs introduced by coercion
  </code></pre>
  
  <p>The "NAs introduced by coercion" seems to happen as a first column is not a number. So, I've tried to run the code against <code>dat[-1]</code> but result is the same.</p>
  
  <p>What am I missing or doing wrong?</p>
  
  <p>Thanks a lot in advance.</p>
  
  <p>=== UPDATE #1 ===</p>
  
  <p>Output on str and factor:</p>
  
  <pre><code>&gt; str(dat)
  'data.frame':   14634 obs. of  3 variables:
   $ V3 : Factor w/ 10062 levels "000880bf-6cb7-4c4a-9a9d-1c0a975b52ba",..: 7548 6585 3670 5336 9181 6429 62 410 7386 9409 ...
   $ V8 : Factor w/ 5561 levels "1000120","1000910",..: 835 3996 443 65 1289 2084 582 695 3666 4787 ...
   $ V12: Factor w/ 395 levels "100.0","101.0",..: 25 278 249 256 352 249 1 88 361 1 ...
  
  &gt; dat[,1] = factor(dat[,1])
  &gt; str(dat)
  'data.frame':   14634 obs. of  3 variables:
   $ V3 : Factor w/ 10062 levels "000880bf-6cb7-4c4a-9a9d-1c0a975b52ba",..: 7548 6585 3670 5336 9181 6429 62 410 7386 9409 ...
   $ V8 : Factor w/ 5561 levels "1000120","1000910",..: 835 3996 443 65 1289 2084 582 695 3666 4787 ...
   $ V12: Factor w/ 395 levels "100.0","101.0",..: 25 278 249 256 352 249 1 88 361 1 ...
  
  &gt; dd &lt;- dist(dat)
  Warning message:
  In dist(dat) : NAs introduced by coercion
  &gt; hc &lt;- hclust(dd)                # apply hirarchical clustering
  Error in hclust(dd) : NA/NaN/Inf in foreign function call (arg 11)
  </code></pre>
  
  <p>=== UPDATE #2 ===</p>
  
  <p>I would not like to remove the first column as there could be multiple clicks for the same user which I consider to be important for the analysis.</p>