I've done this in the past with a little bit of jiggery-pokery.
So the PRIO-GRID structure can be matched with country codes, but you have to download them first from their website.
I saved them as
priogrid.csv in the code below.
In addition, they use a coding scheme no one uses except for the incidental political scientist.
Hence they need to be matched with a more common coding scheme like ISO.
For this I used the
Here's my shot at this: maybe not the cleanest way but it works (for what I need though).
I am sure there might be some directer way to match the cells with the country codes but I haven't found out how yet.
I guess you can adapt it to suit your needs.
Specifically matching it with your shape file for national boundaries.
#get GW code for African countries
poly <- cshp(date=as.Date("2014-12-31"), useGW=TRUE) #load map
poly$continent <- countrycode(poly$ISONAME,
"country.name", "continent", warn = TRUE)
gw <- as.vector(na.omit(poly$GWCODE[poly$continent == "Africa"])) #GW country code
#get GID for African countries
gid.gw <- fread("priogrid.csv") #NB: this needs to be downloaded
gid <- gid.gw$gid[gid.gw$gwno %in% gw]
#subset priogrid to cells in Africa
grid <- readOGR(dsn = "priogrid_cellshp", layer = "priogrid_cell")
grid <- grid[grid$gid %in% gid,]
#add country code
intermediate <- data.table(gwno = poly$GWCODE, iso = poly$ISO1AL3)
gid.gw <- merge(gid.gw, intermediate, all.x=TRUE)
grid <- merge(grid, gid.gw, all.x = TRUE)