Learn R Programming

timeDF (version 0.9.0)

extract_with_periodDF: Extract time records from timeDF object within periods of periodDF object

Description

Extract time records from timeDF object that are included within periods of periodDF object. periodDF object has one of some timescales, and how this function extracts time records depends on the timescale. Also, when the time is on either end of a time period, whether the time record is extracted or not depends on the include argument. "both" means including both sides, "right" means including only the right side, "left" means including only the left side, and "none" does not include any sides.

Usage

extract_with_periodDF(timeDF, periodDF, include, modStart = 0, modEnd = 0,
units = NULL, outputAsBool = FALSE)

Value

If periodDF does not have labels, timeDF object or a boolean object is returned. If periodDF has labels, a list of timeDF objects with keys of label names or a list of boolean vectors with label name keys is retruned.

Arguments

timeDF

timeDF object

periodDF

periodDF object

include

character element that specifies whether each end of periods is included or not

modStart

values to be added for starts of periods.

modEnd

values to be added for ends of periods.

units

units for values of modStart and modEnd

outputAsBool

boolean value; if this is TRUE, the return value is a boolean vector or boolean vectors that represent(s) records to be extracted

See Also

timeDF-class periodDF-class timeDF-package

Examples

Run this code
time_df = data.frame(
    time = c("2023-01-01 12:00:00",
             "2023-01-21 12:00:00",
             "2023-02-10 12:00:00",
             "2023-03-02 12:00:00",
             "2023-03-22 12:00:00",
             "2023-04-11 12:00:00"
    ),
    value = c(123, 144, 150, 100, 130, 145)
)
timeDF = as.timeDF(time_df)

period_df = data.frame(
    start = c("2023-01-01",
              "2023-02-01",
              "2023-03-01"),
    end = c("2023-01-31",
            "2023-02-28",
            "2023-03-31"),
    label = c("Jan", "Feb", "Mar")
)
periodDF = as.periodDF(period_df, "date", label_var = "label")

extract_with_periodDF(timeDF, periodDF, "both")

Run the code above in your browser using DataLab