9.3 Crop and mask the temperature raster using quebec boundary.

First, crop() will decrease the extent of the raster using the extent of another spatial object and mask() keeps the raster values only in the area of interest and set the rest to NA. Because crop() from raster expects a sp object we will use transform the polygon first.

temp_crop <- crop(temp6, as(qc_simple, "Spatial"))
temp_mask <- mask(temp_crop, qc_simple)