Learn R Programming

DTSg (version 0.6.0)

setCols.DTSg: Set Columns' Values

Description

Set the values of columns, add columns to and/or remove columns from a DTSg object. The values can optionally be set for certain rows only.

Usage

# S3 method for DTSg
setCols(
  x,
  i,
  cols = self$cols(class = "numeric")[1L],
  values,
  clone = getOption("DTSgClone"),
  ...
)

Arguments

x

A DTSg object (S3 method only).

i

An integerish vector indexing rows (positive numbers pick and negative numbers omit rows) or a filter expression accepted by the i argument of data.table. Filter expressions can contain the special symbol .N.

cols

A character vector specifying the columns whose values shall be set. The values of the .dateTime column cannot be set.

values

A vector, list or list-like object (e.g. data.table) of replacement and/or new values accepted by the value argument of data.table's set function. NULL as a value removes a column.

clone

A logical specifying if the object is modified in place or if a clone (copy) is made beforehand.

Not used (S3 method only).

Value

Returns a DTSg object.

See Also

DTSg, data.table, .N, cols, list, set

Examples

Run this code
# NOT RUN {
# new DTSg object
x <- DTSg$new(values = flow)

# cap river flows to 100
## R6 method
x$setCols(i = flow > 100, cols = "flow", values = 100)

## S3 method
setCols(x = x, i = flow > 100, cols = "flow", values = 100)

# }

Run the code above in your browser using DataLab