title: convert matrix to raster in R
body: <p>I have a matrix data with spatial coordinates and one variable. The spatial resolution is 1000 meters.</p>
  
  <pre><code>&gt; str(dat1)
  &gt; List of 3
  &gt; $ x: num [1:710] 302340 303340 304340 305340 306340 ...
  &gt; $ y: num [1:1241] 5431470 5432470 5433470 5434470 5435470 ...
  &gt; $ z: num [1:710, 1:1241] 225 225 225 225 225 ...
  </code></pre>
  
  <p>I want to convert it into raster format.</p>
  
  <pre><code>&gt; dat1$x[1:10]
  &gt; [1] 302339.6 303339.6 304339.6 305339.6 306339.6 307339.6 308339.6 309339.6 310339.6 311339.6
  &gt; dat1$y[1:10]
  &gt;  [1] 5431470 5432470 5433470 5434470 5435470 5436470 5437470 5438470 5439470 5440470
  </code></pre>
  
  <p>I used the following code to do it. But the resolution I get is not the same with that I have. Any better way to get the same resolution with my real data?</p>
  
  <pre><code>&gt; r &lt;-raster(
               dat1$z,
               xmn=range(dat1$x)[1], xmx=range(dat1$x)[2],
               ymn=range(dat1$y)[1], ymx=range(dat1$y)[2], 
               crs=CRS("+proj=utm +zone=11 +datum=NAD83")
              )
  &gt; r
  
  class       : RasterLayer 
  dimensions  : 710, 1241, 881110  (nrow, ncol, ncell)
  resolution  : 571.3135, 1746.479  (x, y)
  extent      : 302339.6, 1011340, 5431470, 6671470  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=utm +zone=11 +datum=NAD83 
  data source : in memory
  names       : layer 
  values      : 13.65059, 248.6229  (min, max)
  </code></pre>