extract_shift_time: Extract Shift Time from a Lagged Correlation Object

View source: R/10-extract_data.R

extract_shift_timeR Documentation

Extract Shift Time from a Lagged Correlation Object

Description

Retrieves the shift time(s) from a lagged correlation object, with an option to process and return them as numeric values.

Usage

extract_shift_time(object, numeric = TRUE)

Arguments

object

An object that includes a shift_time component, expected to be in a specific format (string or numeric).

numeric

A logical value; if TRUE, the function will convert shift_time values into numeric means, otherwise, it will return raw shift times. Defaults to TRUE.

Details

The function first retrieves the shift_time component of the input object. If the numeric parameter is set to TRUE, the function proceeds to convert the shift time(s) to numeric format. It removes parentheses, splits the string at commas, takes the first element, converts it to numeric and calculates the mean if there are multiple values. This is all done using a chain of lapply and stringr functions. If numeric is FALSE, the raw shift time data is returned as is.

Value

If numeric is TRUE, returns a numeric vector of the mean shift times extracted from the object's shift_time attribute. If numeric is FALSE, returns the raw shift time values as they are stored in the object.

Note

The object is expected to have an accessible shift_time attribute. The function relies on the stringr package for string manipulation.

Examples

data("object", package = "laggedcor")
extract_shift_time(object = object, numeric = TRUE)
extract_shift_time(object = object, numeric = FALSE)

jaspershen/laggedcor documentation built on Nov. 9, 2023, 3:44 p.m.