db.add {RGeostats} | R Documentation |
Add one or several vectors to an already existing db-class
db.add(db, ..., locnames=NA, loctype="z", names=NA, auto.locate = FALSE, type.locate=TRUE, flag.replace=FALSE, flag.alias=FALSE, flag.number=TRUE, varbase=NA, locrank = NA, radix=NA)
db |
The |
... |
List of the vectors to be added. The vectors are named after their argument names. |
locnames |
List of locators assigned to the newly created variables |
loctype |
Generic name of the locators, only used if the type.locate=TRUE and auto.locate=FALSE |
names |
Array of names that should be used to rename the newly created variables. Note that if the length of this argument does not match the number of variables newly added, a message is issued and the renaming activity is ignored. |
auto.locate |
When TRUE, the locators of the new variables are assigned according to the variable name. |
type.locate |
When TRUE, the locators of the new variables are generated using 'loctype' combined with the index of the newly created field |
flag.replace |
When TRUE, any variable with a name similar to the name of one of the added variables is deleted beforehand |
flag.alias |
Deprecated. Use 'flag.number' instead (with 'radix') |
flag.number |
This parameter is only used when 'radix' is provided. When TRUE, the name is composed of the radix followed by the rank of the added variable (within the input argument). When FALSE, the name is simply set to the radix. |
varbase |
Deprecated. Use 'radix' instead (with 'flag.number') |
locrank |
When defined together with the flag type.locate, the added variables receive locators of type loctype, and with a rank starting from locrank. |
radix |
The new variables can be named automatically if radix is provided. The names are generated according to the following syntax: 'radix'. 'rank' where 'rank' corresponds to the index of the new field. |
The '...' argument may contain a series of variables, defined by their names (no quote is required). The variables are added to the data base. An algorithm is then performed to set the locators to these new variables which functions as follows:
If the argument 'locnames' is provided, the i-th variable will be set to the locator given by locator[i] (if it is an authorized locator name) or to NA otherwise. The field whose index exceeds the length of the argument 'locnames', will be set to 'NA'.
Otherwise, if the argument 'type.locate' is switch ON, the i-th variable will be set to the locator obtained by combining the generic locator name 'loctype' with the index of the field 'i'
Otherwise, if the argument 'autoname' is switch ON, the name of the variable will be used to set the locator (if it is an authorized locator name).
Otherwise, the locator is set to NA
If db.add() is used to add a new variable while performing a calculation, all the samples will be processed, regardless of any possible active selection.
If the Db corresponds to a Grid, samples are ordered as described in the
'Details' section of db-class
.
The db-class
where the vectors have been added
data(Z_data.db) # Load the Documentation Points Db Z_data.db # Print a short contents of the Db # Add a new variable called "New Variable" (set to 0). No locator defined Z_data.db <- db.add(Z_data.db, New_Variable = 0) # Note that the quotes (for the variable on the left-side of the '=' sign) # are compulsory as the name is the concatenation of two words # Otherwise, it is optional # The quotes should not be used on the right of the = sign. print(Z_data.db) # Print the contents # The locators are "NA","x1","x2","z1","z2","NA" # Add one new variable (set to 1) and set its locator explicitely to "z1" Z_data.db <- db.add(Z_data.db,z1=1) print(Z_data.db) # Print the contents # The locators are "NA","x1","x2","NA","z2","NA","z1" # Add a variable as the result of a calculation on already existing fields Z_data.db <- db.add(Z_data.db,"Calculated Variable"=z1+2) # Check the newly created variable is set uniformely to 3 print(Z_data.db,flag.stats=TRUE,name="Calculated Variable") # Clean up rm(Z_data.db)