title: R 'merge' is changing data in the merging dataframes
body: <p>I am having some trouble with the merge command in R, I am trying to place values into bins that I can then use as color values for a plot. I would like to keep the quantile bin values though to use as a legend, so I am merging that back to the original dataframe as well.</p>
  
  <p>The problem I have is that when I do this the original values get changed when I merge the quantiles back to the original dataframe to make a new dataframe. I am probably doing something obviously wrong, but have been toying with this problem for some time now and searching 'merge is changing data' does not return anything on the type of unintentional 'changing data' I am having trouble with. Thanks!</p>
  
  <pre><code># create random data
  x=rnorm(100,100,25)
  x=as.data.frame(x)
  
  # create bins to place the data in
  quantiles=quantile(x,c(seq(.05,.95,.05)))
  quantiles=as.data.frame(quantiles)
  
  # create bin number to merge upon later
  quantiles$binnumber=c(1:dim(quantiles)[1])
  
  # create bin number in x to merge upon later
  x$binnumber=tapply(x$x,cut(x$x,quantiles$quantiles))
  
  merged=merge(x,quantiles,by="binnumber")
  
  # should work right? note the difference in summary,
  # it seems the high and low values got changed
  # somehow while the middle values did not.
  
  summary(x$x)
  
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   39.35   83.15   95.67   98.92  116.30  190.80 
  
  summary(merged$x)
  
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   60.62   84.46   95.67   97.92  114.20  136.40 
  </code></pre>