movAvg: Moving average windows

Description Usage Arguments Value Examples

View source: R/movAvg.R

Description

Smooth a numeric serie with a moving average windows

Usage

1
movAvg(df, k, pos)

Arguments

df

data frame with the serie that you want to smooth. By default, t he function uses column 2.

k

numeric value with windows size., e.g.: 5

pos

string with the position of the window:

  • 'izq': left aligned. The output value is on the left, so the function weights the (k - 1) values at the right side.

  • 'der': right aligned. The output value is on the right, so the function weights the (k - 1) values at the left side.

  • 'cen': center. The output value is in the middle of the window.

Value

data frame with the smooth serie.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Relative path to raw data
full_path <- system.file('extdata', package = "hydroToolkit")

# Apply function
cuevas <- read_IANIGLA(file = 'Cuevas.csv', path = full_path)   
               
# Get air temperature
cuevas_tair <- cuevas[ , 1:2]

# Create a moving average serie of Tair
Tair_mov <- movAvg(df = cuevas_tair, k = 10, pos = 'izq')

hydroToolkit documentation built on July 2, 2020, 1:04 a.m.