[R-sig-Geo] How to rescale a raster in R?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sun Mar 23 20:35:48 CET 2014


require(raster)
r = raster()
r[] = rnorm(180*360)
plot((r-cellStats(r,"min"))/(cellStats(r,"max")-cellStats(r,"min")))

raster::scale, like base::scale, centers to mean zero and scales to unit
variance.

On 03/23/2014 06:40 PM, Manuel Spínola wrote:
> Dear list members,
> 
> I want to rescale a raster between 0 and 1, how can I do that in R?
> 
> I know that there is a scale function in the raster package, but I don´t
> know how to use it for rescaling.
> 
> Best,
> 
> Manuel
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140323/5e638e4e/attachment.bin>


More information about the R-sig-Geo mailing list