Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle Identification #2

Open
mechengjoe opened this issue Mar 16, 2021 · 0 comments
Open

Cycle Identification #2

mechengjoe opened this issue Mar 16, 2021 · 0 comments

Comments

@mechengjoe
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant