digi: Creates a digital ON-OFF function which is toggled for...

View source: R/digi.R

digiR Documentation

Creates a digital ON-OFF function which is toggled for specific windows

Description

1. This function returns a 2 column dataframe with columns X and Y.
2. The Y column is mostly 1( inv = F (default)) or 0( inv = T) with specific *windows* wherein the function is toggled in the opposite direction .
3. These *windows* are defined by the *win_df* dataframe called a window dataframe

Usage

digi(X, win_df = win_d, inv = T)
digi(X, win_df = win_d, inv = F)
digi(X, win_df = win_d)

Arguments

X

The X axis values for which the Y values need to be defined

win_df

1. This is referred to as the *windows* dataframe.
2. It MUST be a 2 column dataframe.
3. The column names MUST be *min* and *max*.
4. Each entry of this dataframe defines a window within which the function must be toggled.
5. The max and min values of this window MUST be less than and greater than the max and min values of the X sequence.

inv

1. A boolean bit, set to FALSE by deafult.
2. When inv = FALSE, Y = 0 within the windows and Y = 1 otherwise.
3. When inv = TRUE, Y = 1 within the windows and Y = 0, otherwise

Value

The returned value is a 2 column dataframe with names 'X' and 'Y'

Author(s)

Chitran Ghosal

Examples

#Let's create a sequence within X = 0 and X = 20 with windows at (12, 14) and (18, 19)
X <- seq(10, 20, by = 0.01)
win_d <- data.frame(c(12, 18), c(14, 19))
names(win_d) <- c('min', 'max')

#Call the digi function
df <- digi(X, win_df = win_d)
df1 <- digi(X, win_df = win_d, inv = T)

#plot the data
subplot(c(2,1))
plot(df$X, df$Y, type = 'l', col = 'red')
plot(df1$X, df1$Y, type = 'l', col = 'blue')
subplot(c(1,1))

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.