Skip to content

Cycle Identification #2

@mechengjoe

Description

@mechengjoe

This package is awesome!!! Is there an ability to apply an identifying factor on the cycles in the data set? I didn't see anything digging through what you have.

Below illustrates what I am looking for and how I was able to rig together a solution for my application with time series data. This is a small sample of my dataset df.txt which represents about 3 days of a dataset that covers a few years.

An example of the data looks like:

Time Value
2018-08-10 06:00:00 760.6917
2018-08-10 06:01:00 761.0291
2018-08-10 06:02:00 760.9166
2018-08-10 06:03:00 761.2542
2018-08-10 06:04:00 761.1416
2018-08-10 06:05:00 762.5291

I used the indices from the FindPeaks() function and converted those to matching timestamps from my dataset and then used row_number() to apply a quick and dirty identifying factor.

library(lubridate)
library(dplyr)

p <- FindPeaks(df$Value, R=1.05, smooth = FALSE)

cycleID <- tibble(Time = c(df$Time[1], df$Time[1] + lubridate::dminutes(p$indices[-1]))) %>% 
  dplyr::mutate(Cycle = row_number()) %>% 
  dplyr::select(Cycle, Time)

df_out <- left_join(df, cycleID, by = "Time") %>% 
  tidyr::fill(Cycle)

The output looks like this with the new ID variable.

Time Value Cycle
2018-08-10 06:00:00 760.6917 1
2018-08-10 06:01:00 761.0291 1
2018-08-10 06:02:00 760.9166 1
2018-08-10 06:03:00 761.2542 1
2018-08-10 06:04:00 761.1416 1
2018-08-10 06:05:00 762.5291 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions