modify_indicator: Modify indicator to add new attribute

Description Usage Arguments Value See Also Examples

View source: R/indicator-build.R

Description

Use modifying function to modify indicator timeseries, e.g. add new attribute to existed indicator timeseries.

Usage

1
2
3
4
5
6
7
8
9
modify_indicator(
  ts_indicator,
  modify_fun,
  ...,
  replace_exist = FALSE,
  date_index_field = c("date"),
  key_fields = NULL,
  parallel = getOption("zstmodelr.common.parallel", TRUE)
)

Arguments

ts_indicator

A dataframe of indicator timeseries to modify.

modify_fun

A function of modify indicator.

...

Params to modify_fun.

replace_exist

A logic flag to determine whether to replace existed attribute fields. Default FALSE means to not replace existed field.

date_index_field

Name of date index field of ts_indicator, default 'date'.

key_fields

A character vector of key fields, which identify unique observation in each date. Default NULL means to not divide data into groups.

parallel

A logic to determine whether to use parallel processing. Default TRUE means to use parallel processing.

Value

A dataframe of modified indicator timeseries if succeed, otherwise NULL.

See Also

Other indicator build functions: compute_indicator(), create_indicator()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Not run: 

# modify ts_indicator with customized ind_attr_def_fun

# create attribute definition function of customized attribute
attr_fun <- function(date, stkcd, ...) {
  "attr_value"
}
ind_attr_def_fun <- create_attribute_def_fun(
  attr_name,
  attr_fun = attr_fun
)
# modify existed ts_indicators
ts_modify_indicator <- modify_indicator(ts_modify_indicator,
  modify_fun = ind_attr_def_fun,
  date_index_field = "date",
  key_fields = "stkcd",
  parallel = FALSE
)


# modify ts_indicator with pre-defined ind_attr_def_fun

# create definition function of pre-defined attribute of indcd
new_attr_indcd <- ind_attr_def_indcd(stock_db)

# modify existed ts_indicators
ts_indicator <- modify_indicator(
  ts_indicator = ts_indicator,
  modify_fun = new_attr_indcd,
  replace_exist = FALSE,
  date_index_field = "date",
  key_fields = "stkcd",
  parallel = FALSE
)

## End(Not run)

chriszheng2016/zstmodelr documentation built on June 13, 2021, 8:59 p.m.