title: Masking raster from data in SpatialGridDataFrame and SpatialPolygonsDataFrame
body: <p>I am trying to mask a raster file by including only some specific area (‘Koeppen Geiger’ climatic zones) with several locations. I got an error message running the final line of code: </p>
  
  <blockquote>
    <p>Error in (function (classes, fdef, mtable)  :    unable to find an
    inherited method for function ‘mask’ for signature
    ‘"SpatialGridDataFrame", "SpatialPolygonsDataFrame"’</p>
  </blockquote>
  
  <p>.</p>
  
  <pre><code>    ##Read Countries file
  library(sp)
  library(maptools)
  library(rworldmap)
  countries = readShapeSpatial("D:/Studies/PhD/SCI/modeling/ne_10m_admin_0_countries/ne_10m_admin_0_countries.shp") [enter link description here][1]
  asia.zone = countries[countries$ADMIN=="South Korea"|
                          countries$ADMIN=="North Korea"|
                          countries$ADMIN=="Japan"|
                          countries$ADMIN=="China"|
                          countries$ADMIN=="Taiwan",]
  
  ##Read Koeppen Geiger’ climatic zones
  tst &lt;- read.csv('D:/Studies/PhD/SCI/modeling/Koeppen-Geiger-ASCII.csv',as.is=TRUE) [enter link description here][1]
  tst.l &lt;- tst [tst$Cls=="Cfc"|
                  tst$Cls=="Cfa"|
                  tst$Cls=="Cfb"|
                  tst$Cls=="Cwa"|
                  tst$Cls=="Cwb"|
                  tst$Cls=="Aw"|
                  tst$Cls=="As"|
                  tst$Cls=="Am"|
                  tst$Cls=="Dwd"|
                  tst$Cls=="Dwb"|
                  tst$Cls=="Dwa"|
                  tst$Cls=="Dwc",]
  #convert to sp SpatialPointsDataFrame
  coordinates(tst.l) = c("Lon", "Lat")
  # promote to SpatialPixelsDataFrame
  gridded(tst.l) &lt;- TRUE
  # promote to SpatialGridDataFrame
  tst.lsGDF = as(tst.l, "SpatialGridDataFrame")
  # mask the specific climate zone from some locations
  asia.zone2 &lt;- mask(tst.lsGDF,asia.zone)
  </code></pre>