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 7564597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:56:40+00:00 2026-05-30T13:56:40+00:00

For instance, let’s say you have ~10 years of daily 1 min data for

  • 0

For instance, let’s say you have ~10 years of daily 1 min data for the volume of instrument x as follows (in xts format) from 9:30am to 4:30pm :

    Date.Time               Volume        
    2001-01-01 09:30:00     1200
    2001-01-01 09:31:00     1110
    2001-01-01 09:32:00     1303

All the way through to:

    2010-12-20 16:28:00     3200
    2010-12-20 16:29:00     4210
    2010-12-20 16:30:00     8303

I would like to:

  • Get the average volume at each minute for the entire series (ie average volume over all 10 years at 9:30, 9:31, 9:32…16:28, 16:29, 16:30)

How should I best go about:

  • Aggregating the data into one minute buckets
  • Getting the average of those buckets
  • Reconstituting those “average” buckets back to a single xts/zoo time series?

I’ve had a good poke around with aggregate, sapply, period.apply functions etc, but just cannot seem to “bin” the data correctly.

It’s easy enough to solve this with a loop, but very slow. I’d prefer to avoid a programmatic solution and use a function that takes advantage of C++ architecture (ie xts based solution)

Can anyone offer some advice / a solution?

Thanks so much in advance.

  • 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-05-30T13:56:41+00:00Added an answer on May 30, 2026 at 1:56 pm

    First lets create some test data:

    library(xts) # also pulls in zoo
    library(timeDate)
    library(chron) # includes times class
    
    # test data
    x <- xts(1:3, timeDate(c("2001-01-01 09:30:00", "2001-01-01 09:31:00", 
        "2001-01-02 09:30:00")))
    

    1) aggregate.zoo. Now try converting it to times class and aggregating using this one-liner:

    aggregate(as.zoo(x), times(format(time(x), "%H:%M:%S")), mean)
    

    1a) aggregate.zoo (variation). or this variation which converts the shorter aggregate series to times to avoid having to do it on the longer original series:

    ag <- aggregate(as.zoo(x), format(time(x), "%H:%M:%S"), mean)
    zoo(coredata(ag), times(time(ag)))
    

    2) tapply. An alternative would be tapply which is likely faster:

    ta <- tapply(coredata(x), format(time(x), "%H:%M:%S"), mean)
    zoo(unname(ta), times(names(ta)))
    

    EDIT: simplified (1) and added (1a) and (2)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say for an instance I have this string: var a=23434,bc=3434,erd=5656,ddfeto='dsf3df34dff3',eof='sdfwerwer34',wer=4554; How should I
Let's say I want some instance of String behave differently from other, normal instances
Let's say I have a MyObject instance which is not initialized: var a:MyObject =
Let's say I have a class Foo with some primitive instance variables. I initialize
For instance, let's say I have a User model. Users have things like logins,
Let's say we have a class foo which has a private instance variable bar
Let's say for instance: I have two tables: old_data and new_data . Both old_data
Let's say I have 2 instance of a class called 'Animal'. Animal has 3
For instance, let's say I have a snippet of code, which I'd like to
I have following classes. In instance of BE (let's say objBE) i want to

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.