title: Fast Calculation Matrix in R
body: <p>I have simple code, but it took 0.006 sec for one iteration using small data set, i'm afraid because i'm gonna use this on large data set. here is my code</p>
  
  <pre><code>d1 = matrix(0, nrow(x), num.clust)
  for(i in 1:ncol(d.num){
    #For numeric attribute
    d1.temp = (w*(d.num - matrix(rep(as.numeric(num.centroid[i,]), nrows),nrow = nrows, byrow = T)))^2
  
    d1[,i] = rowSums(d1.temp)
  }
  </code></pre>
  
  <p>and this is data frame that i used</p>
  
  <pre><code>&gt; head(d.num)
  x3        x4
  4.842316 11.754403
  6.405585 11.643502
  6.590780 11.478245
  6.656699 11.293404
  &gt; num.centroid
       [,1]     [,2]
  [1,] 7.605837 12.59816
  [2,] 7.895469 12.92275
  </code></pre>
  
  <p>w is data frame that has size with d.num. Any suggest to reduce time execution for this case ?</p>