title: Unable to plot kernel density in MASS package - In min(x) : no non-missing arguments to min; returning Inf
body: <p>When trying to plot my data I get these error messages:</p>
  
  <pre><code>1: In min(x) : no non-missing arguments to min; returning Inf
  2: In max(x) : no non-missing arguments to max; returning -Inf
  </code></pre>
  
  <p>This reproducible code works:</p>
  
  <pre><code># some dummy data
  library(mvtnorm)
  dat &lt;- rmvnorm(10000, mean=c(x=4,y=4), sigma=matrix(c(1,0.5,0.5,1), ncol=2))
  dat &lt;- as.data.frame(dat)
  
  # 2d density plot
  library(MASS)
  kdexy &lt;- kde2d(dat$x,dat$y, n=50)
  image(kdexy, col=grey(seq(1,0.2,length=10)))
  </code></pre>
  
  <p>But using my real data doesn't:</p>
  
  <pre><code>kdexy &lt;- kde2d(temp$V1, temp$V2, n=50)
  image(kdexy, col=grey(seq(1,0.2,length=10)))
  </code></pre>
  
  <p>Yet the structure of the two data sets is the same (the dummy data [dat] and the real data [temp]):</p>
  
  <pre><code>&gt; str(dat$x)
   num [1:80000] 0.669 0.609 -0.633 0.565 0.559 ...
  &gt; str(temp$V1)
   num [1:823180] 0 0 0 0 0.0146 ...
  &gt; summary(dat$x)
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  -4.2270 -0.1902  0.4841  0.4900  1.1600  5.3570 
  &gt; summary(temp$V1)
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  -1.0000  0.0000  0.0000 -0.0289  0.0000  0.9844 
  &gt; range(dat$x)
  [1] -4.227400  5.357184
  &gt; range(temp$V1)
  [1] -1.000000  0.984375
  &gt; str(temp$V2)
   num [1:823180] 1 1 15.5 15.5 18.5 ...
  &gt; summary(temp$V2)
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
     1.00    1.00   18.45   23.55   35.96  116.10 
  &gt; range(temp$V2)
  [1]   1.0000 116.0829
  </code></pre>
  
  <p>They are both stored in dataframes and the only difference I'm aware of is the length, and that <code>temp$V1</code> is bounded at <code>-1</code> and <code>1</code>.</p>
  
  <p>The output of <code>kdexy &lt;- kde2d()</code> differs between the two datasets. In the example data, the <code>Z</code> sections is populated with very small numbers; in the real dataset, every point is filled with 'NaN'.</p>