Hello,

I have not worked with rasters much in R and am having a bit of trouble.

I have a raster of global population and a second raster of countries
identified by UN code (both at 1/2 degree resolution, but with different
extents).  Ultimately I would like to end up with a raster where each
country's population is rescaled to N(0,1).

Can someone suggest the best way to do this?

So far I have been able to mask the population raster to a given country
and perform the rescale (with the plan to loop over countries) .  I'm stuck
on how to "reassemble" into a complete raster with all the countries.

#Code thus far -- although I'm sure there is a better way.
rasterCountriesUN[rasterCountriesUN != 840] <- NA  #Mask countries not of
interest

rasterCountriesUN[rasterCountriesUN == 840] <- 1  #replace the UN code with
1

cropPop2010 <- rasterCountriesUN*rasterPop2010  # crop population data
raster

cropPop2010[cropPop2010>0] <- scale(cropPop2010[cropPop2010>0]) #rescale
cells > 0 (i.e., with people)
# I have other calculations to do here using the scaled population data.

###??? How do I store these results and move to the next country?  Or is
there  better way to go about this?


Many thanks,

-- 
Gordon Holtgrieve, Ph.D.
Assistant Professor
University of Washington
School of Aquatic & Fishery Sciences
1122 NE Boat Street
Box 355020
Seattle, WA 98105 USA
1-206-616-7041
skype: gholtgrieve

	[[alternative HTML version deleted]]

