View source: R/moving_averages.R
add_EMA.data.frame | R Documentation |
method for the class of objects data.frame
for computing the Exponential Moving Average and adding to the
dataset in a tidy way.
method for the class of objects data.frame
for computing the Simple Moving Average and adding to the
dataset in a tidy way.
## S3 method for class 'data.frame'
add_EMA(object, variable = "Close", n = 10, smooth = 2, na.rm = TRUE)
## S3 method for class 'data.frame'
add_SMA(object, variable = "Close", n = 10, na.rm = TRUE)
variable |
the name of the variable of which we would compute the moving average. |
n |
integer, the number of length of the moving average. |
smooth |
numeric, a parameter to use for smoothing the moving average. |
na.rm |
logical, |
a tibble with one more column named as EMA_
+ variable
, _n
.
a tibble with one more column named as SMA_
+ variable
, _n
.
df <- data.frame(x = runif(1000, 0, 10))
df <- add_EMA(df, variable = "x", n = 10)
df <- data.frame(x = runif(1000, 0, 10))
# the new column will be named as "SMA_x_10"
df <- add_EMA(df, variable = "x", n = 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.