setCols.DTSg | R Documentation |
Changes the values of columns, adds columns to and/or removes columns from a
DTSg
object. The values can optionally be set for certain rows only.
## S3 method for class 'DTSg'
setCols(
x,
i,
cols = self$cols(class = "numeric")[1L],
values,
clone = getOption("DTSgClone"),
...
)
x |
A |
i |
An integerish vector indexing rows (positive numbers pick and
negative numbers omit rows) or a filter expression accepted by the |
cols |
A character vector specifying the columns whose values shall be
set. Another possibility is a character string containing comma separated
column names, for example, |
values |
A vector, |
clone |
A logical specifying if the object shall be modified in place or if a deep clone (copy) shall be made beforehand. |
... |
Not used (S3 method only). |
Returns a DTSg
object.
cols
, getOption
# new DTSg object
x <- DTSg$new(values = flow)
# cap river flows to 100
## R6 method
x$setCols(
i = flow > 100,
cols = "flow",
values = 100
)$print()
## 'set()' is a "hidden" R6 alias for 'setCols()'
x$set(
i = flow > 100,
cols = "flow",
values = 100
)$print()
## S3 method
print(setCols(
x = x,
i = flow > 100,
cols = "flow",
values = 100
))
# set measurement unit with the help of 'units'
if (requireNamespace("units", quietly = TRUE)) {
## R6 method
x$setCols(
cols = "flow",
values = units::set_units(x["flow"], "m^3/s")
)$print()
## S3 method
print(setCols(
x = x,
cols = "flow",
values = units::set_units(x["flow"], "m^3/s")
))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.