R/randomize.R

Defines functions .randomize

.randomize <- function(x, ...) {
	if (!hasValues(x)) {
		return(x)
	}
	nl <- nlayers(x)
	if (nl > 1) {
		y <- brick(x, values=FALSE)
		for (i in 1:nl) {
			y <- setValues(y, sample(getValues(x[[i]])), layer=i)
		}
		y
	} else {
		setValues(x, sample(getValues(x)))
	}
}

Try the raster package in your browser

Any scripts or data that you put into this service are public.

raster documentation built on Jan. 5, 2021, 3:01 a.m.