View source: R/interpolate_cgm.R
| interpolate_cgm | R Documentation |
Interpolates continuous glucose monitoring (CGM) data onto the same
iglu-compatible, midnight-aligned full-day grid used internally by
cgmguru's event-detection functions. The interpolation is implemented in C++
and is intended for users who want to inspect or reuse the preprocessed grid
behind detect_all_events,
detect_hyperglycemic_events, and
detect_hypoglycemic_events.
For each subject, interpolate_cgm() builds an equally spaced grid at
reading_minutes intervals. If reading_minutes is omitted, it is
inferred per subject from the median positive timestamp difference. Glucose
values are linearly interpolated only across gaps up to inter_gap;
larger gaps are treated as missing and removed from the returned data,
preserving segment boundaries used by event calculation.
The GRID-family functions grid, maxima_grid, and
excursion do not call this helper automatically; they operate
on the rows supplied by the user unless the caller explicitly passes an
interpolated dataset.
interpolate_cgm(df, reading_minutes = NULL, sort_time = FALSE,
inter_gap = 45)
df |
A dataframe containing CGM data with columns:
|
reading_minutes |
Time interval for the interpolation grid in minutes.
If omitted or |
sort_time |
Logical. If |
inter_gap |
Maximum gap in minutes to interpolate across. Defaults to 45; larger gaps split the event-detection grid. |
A tibble with columns id, interpolated time, and
interpolated gl. Rows inside gaps larger than inter_gap are
omitted.
detect_all_events, detect_hyperglycemic_events, detect_hypoglycemic_events
df <- data.frame(
id = "A",
time = as.POSIXct(c("2026-01-01 00:15:00", "2026-01-01 00:25:00"),
tz = "UTC"),
gl = c(100, 120)
)
interpolate_cgm(df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.