I think it comes down to a problem with the appropriate setting.
Your japanMapB object consists of several metadata and a series of polygons for each form stored in japanMapB@polygons . So you have:
> length(japanMapB$JCODE)
As @PaulHiemstra notes, you have multiple NA values โโin your JCODE variable
> table(is.na(japanMapB$JCODE))
This means that you get NA results when you try to index the municipalities that you want to build.
> table(japanMapB$JCODE==45382,useNA="always")
Wrapping in which solves the following:
which(japanMapB$JCODE == 45382)
source share