Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:39:45+00:00 2026-06-06T02:39:45+00:00

I’ve been working with R just a few months, I have a problem with

  • 0

I’ve been working with R just a few months, I have a problem with a zoo series with data at each five minutes. The are no missing time points in the series, but there are some NaN values on data.

>str(SerieCompleta)
‘zoo’ series from 2011-01-01 to 2011-12-31 23:55:00
 Data: num [1:104737, 1] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, "na.action")=Class 'omit'  num [1:383] 2017 3745 5761 6786 6787 ...
 Index:  POSIXct[1:104737], format: "2011-01-01 00:00:00" "2011-01-01 00:05:00" ...

I need to find the maximum of groups of data, and groups of data should be separated by thirty or more consecutive minutes with zero values.

2011-01-02 05:15:00 0
2011-01-02 05:20:00 0
2011-01-02 05:25:00 0
2011-01-02 05:30:00 0
2011-01-02 05:35:00 0.1 |
2011-01-02 05:40:00 0.2 <--- maximum of group
2011-01-02 05:45:00 0.2 |
2011-01-02 05:50:00 0.1 |
2011-01-02 05:55:00 0.1 |
2011-01-02 06:00:00 0.1 |
2011-01-02 06:05:00 0.1 |
2011-01-02 06:10:00 0   |
2011-01-02 06:15:00 0   |
2011-01-02 06:20:00 0.1 |
2011-01-02 06:25:00 0
2011-01-02 06:30:00 0
2011-01-02 06:35:00 0
2011-01-02 06:40:00 0     thirty or more consecutive minutes with zero values on data
2011-01-02 06:45:00 0
2011-01-02 06:50:00 0
2011-01-02 06:55:00 0
2011-01-02 07:00:00 0.2 |
2011-01-02 07:05:00 2.5 <--- maximum of group
2011-01-02 07:10:00 0 

Output should look like:

2011-01-02 05:40:00 0.2
2011-01-02 07:05:00 2.5

I don’t know if there’s a way to do this using an R feature. Thanks in advance for any suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:39:46+00:00Added an answer on June 6, 2026 at 2:39 am

    I’ll call your data column x (x includes only the numeric data, not the date and times). I’ll further assume that you have no missing time points and that all your time points are 5 minutes apart. Here is a function that will return a two-column matrix, where each row contains the start and end indices of your groups (it ignores zeroes in the beginning and end):

    blocks <- function(x) {
        z <- rle(x==0)
        breaks <- which(z$lengths >= 6 & z$values == TRUE)
        breaks <- breaks[!breaks %in% c(1, length(z$lengths))]
        break.idx <- cumsum(z$lengths)
        cbind(c(1, break.idx[breaks] + 1), c(break.idx[breaks-1], length(x)))
    }
    

    For your data, you will get

    > x
     [1] 0.0 0.0 0.0 0.0 0.1 0.2 0.2 0.1 0.1 0.1 0.1 0.0 0.0 0.1 0.0 0.0 0.0 0.0 0.0
    [20] 0.0 0.0 0.1 2.5 0.0
    > blocks(x)
         [,1] [,2]
    [1,]    1   14
    [2,]   22   24
    

    Now simply apply the which.max function on your groups to get indices with the maximum values:

    > apply(blocks(x), 1, function(i) {which.max(x[i[1]:i[2]]) + i[1] - 1})
    [1]  6 23
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.