calcNewField | R Documentation |
Basic calculation of new Fields by operation '+', '-', '*' or '/'
calcNewField(
x,
y,
op,
x.col = NULL,
y.col = NULL,
quant = NULL,
verbose = TRUE
)
x |
The first |
y |
The second |
op |
which arithmetic should be performed: addition ('+'), substraction ('-'), multiplication ('*') or division ('/'). |
x.col |
the column of the first Field. If empty or NULL all columns are used. |
y.col |
the column of the second Field. If empty or NULL all columns are used. |
quant |
new Quantity definition to use, if NULL it will be guessed. |
verbose |
print some messages. |
A new Field.
Joerg Steinkamp joerg.steinkamp@senckenberg.de
# First define a Source and read a Field
test.dir <- system.file("extdata", "LPJ-GUESS_Runs", "CentralEurope", package = "DGVMTools")
test.Source <- defineSource(name = "Run 1", dir = test.dir, format = GUESS)
test.Field <- getField(source = test.Source, quant = "lai", year.aggregate.method = "mean")
test.Source.2 <- defineSource(name = "Run 2", dir = test.dir, format = GUESS)
test.Field.2 <- getField(source = test.Source.2, quant = "lai", year.aggregate.method = "mean")
# division, result should be 1 or NA everywhere since Fields are the same
# (NAs come wherever the Field is zero)
test.division <- calcNewField(x=test.Field, y = test.Field.2, op = "/")
print(plotSpatial(test.division))
# subtraction, result should be 0 everywhere since Fields are the same
test.subtraction <- calcNewField(x=test.Field, y = test.Field.2, op = "-", verbose = FALSE)
print(plotSpatial(test.subtraction))
# addition, select Total only and compare to original
test.addition <- calcNewField(x=test.Field, y = test.Field.2,
x.col = "Total", y.col = "Total", op = "+")
print(plotSpatial(list(test.addition, test.Field), layers = "Total"))
# multiplication, select a couple of Layers only and compare to original
test.multiplication <- calcNewField(x=test.Field, y = test.Field.2, x.col = c("C3G", "TeBS"),
y.col = c("C3G", "TeBS"), op = "*", verbose = FALSE)
print(plotSpatial(list(test.multiplication, test.Field), layers = c("C3G", "TeBS")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.