Description Usage Arguments Details Value Examples
View source: R/approxExtrapDemand.R
Round all numbers in a matrix or data.frame while ensuring that all rows sum to the same value.
1 |
x |
matrix or data.frame |
n |
numeric specifying the target sum for each row in |
digits |
integer indicating the number of decimal places to be used |
... |
additional arguments (none) |
The main application of roundSum
is to ensure that each row in the
demand matrix specifies exactly the number of cells to be allocated to each
land use category for the respective timestep. It may also be used to convert
the units of demand to number of cells.
A matrix.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## Not run:
## Sibuyan Island
## load observed land use data and create demand scenario
obs <- LulcRasterStack(x=sibuyan$maps,
pattern="lu",
categories=c(1,2,3,4,5),
labels=c("Forest","Coconut","Grass","Rice","Other"),
t=c(0,14))
dmd <- approxExtrapDemand(obs, tout=0:14)
apply(dmd, 1, sum)
## artificially perturb for illustration purposes
dmd <- dmd * runif(1)
apply(dmd, 1, sum)
## use roundSum to correct demand scenario
ncell <- length(which(!is.na(getValues(sibuyan$maps$lu_sib_1997))))
ncell
dmd <- roundSum(dmd, ncell=ncell)
apply(dmd, 1, sum)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.