1

I have a raster with value ranging from 20-34 (r1). I want to create a new raster (r2) with value range from 0 to 1 from r1 that values of r2 are linear correlated with values of r1.

I have searched over and see "corgen" from ecodist package might be my solution in which I may set the correlation r=1 but I find no place to put the value range for the new raster.

Is there any other solution for my problem? Please help!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Check this answer: http://stats.stackexchange.com/questions/15011/generate-a-random-variable-with-a-defined-correlation-to-an-existing-variable – Lucas Fortini Nov 04 '16 at 22:40

1 Answers1

-1

If what you mean to do is a normalisation between 0 and 1, you might want to do the following :

library(raster)

# Create raster
r1 <- raster(ncol=10, nrow=10)
values(r1) <- 1:ncell(r1)

# Get min and max
max <- maxValue(r1)
min <- minValue(r1)

# Normalize by scaling between 0 and 1
r2 <- (r1 - min) / (max - min)

maxValue(r2) # = 1
minValue(r2) # = 0
rnd
  • 28
  • 5