I have two shapefiles. One consists of squared grid cells and contains ... let's say precipitation data. The other one was downloaded from NaturalEarthData and contains country-internal administrative boundaries (e.g. states) ... as a mask layer. How can I add the average of the precipitation of all grid cells that are located within a mask polygon (e.g. a specific state)? Not only for one state but let's say I am actually covering the entire world.
You can use rasterize tool to convert the grid vector into raster. In this tool you need to choose the attribute field that represents the precipitation and choose the x and y cell sizes that matches the grid x, y spacing. The tool is located in
Processing toolbox -> GDAL/OGR tools -> Analysis -> Rasterize (vector to raster) tool
Then use Zonal statistics to calculate the mean (average) of raster precipitation within the polygon.
The above workflow is for QGIS 2.14 and 2.18 and probably QGIS 3.0 (still not yet downloded).