db.replace {RGeostats}R Documentation

Replace the contents of a variable of a Db

Description

Replace the contents of a variable of a Db

Usage

db.replace(db, name, tab, flag.sel = TRUE)

Arguments

db

db-class from which the target variable must be updated

name

Name of the target variable to be updated. If the variable does not already exist, a new variable is created (filled with NA) before being updated using the input array 'tab'.

tab

Array which will update the contents of the target variable. Note that the size of the array must match the total count of samples (if flag.sel=FALSE) or the number of active samples (if flag.sel=TRUE).

flag.sel

When FALSE, the argument 'tab' contains the values for all samples. When flag.sel=TRUE, the argument 'tab' must contain the new values for the active samples only.

When flag.sel=TRUE, the contents of the masked samples are kept unmodified.

Value

The db-class where the target variable has been updated.

Examples

# Create a 10 by 10 grid and operate the selection of a rectangle
a = db.create(nx=c(10,10))
a = db.sel(a,x1 > 3 & x1 < 8 & x2 > 4 & x2 < 8)
a

# Add the random variable 'z1' on the 'whole' grid (Uniform between 0 and 1)
a = db.add(a,z1=runif(100))
a

# Extract unmasked part of uniform variable (tab)
# and modify it into the constant 5
tab = db.extract(a,"z1")
tab = 5 * (tab > 0)

# Replace the previous contents of the uniform variable by the modified tab
b  = db.replace(a,"z1",tab)

# Plot the variable 'z1' (suprressing the selection on the fly)
plot(db.sel(b))

[Package RGeostats version 14.0.10 Index]