add_EMA.data.frame: add_EMA.data.frame

View source: R/moving_averages.R

add_EMA.data.frameR Documentation

add_EMA.data.frame

Description

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.

Usage

## 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)

Arguments

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,

Value

a tibble with one more column named as EMA_ + variable, ⁠_n⁠.

a tibble with one more column named as SMA_ + variable, ⁠_n⁠.

Examples

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)


beniamino98/cryptocompareR documentation built on June 19, 2024, 12:37 a.m.