+ Reply to Thread
Results 1 to 12 of 12

Average data for 30 second intervals with different number of data points

  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Average data for 30 second intervals with different number of data points

    Hope someone can help I'm pulling my hair out. I have exercise data taken every few seconds (every breath). I want to average readings over 30 second intervals. It is not as simple as say averaging 30 rows if there was data every second for 30 seconds as the number of data points in each 30 second interval varies depending on breathing rate, ie there might be data at 1 second, 3 seconds, 5 seconds etc. or 2 seconds, 10 seconds, 15 seconds etc.

    I therefore need a formula/macro that can look at the column with the timing of the data (breath) mm:ss and pick out the rows between 00:00 and 00:30, 00:31 and 00:59, 01:00 and 01:29... etc. and then average another column for those rows, thus giving me 30 second averages. It's the irregular number of rows that is stumping me and currently I'm selecting them manually.

    If anyone has an idea how to solve this I would be grateful!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Average data for 30 second intervals with different number of data points

    Welcome to the forum.

    If anyone has an idea how to solve this ...
    Easy enough if you post a workbook showing the data layout and what you want.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    02-02-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Average data for 30 second intervals with different number of data points

    Quote Originally Posted by shg View Post
    Welcome to the forum.


    Easy enough if you post a workbook showing the data layout and what you want.
    Thanks, I've attached a few columns with the time on the left with a few columns of data I want to average over 30 seconds (vo2, vco2, ve).

    In this example the first 30 seconds is the first 8 rows
    00:00
    00:08
    00:11
    00:15
    00:17
    00:21
    00:25
    00:28
    second 30 seconds is next 5 rows and so on
    00:32
    00:34
    00:38
    00:45
    00:53
    I want it to be able to work out which rows to select so I can use it on different studies with different timings.

    Hope this is making sense, thanks.
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Average data for 30 second intervals with different number of data points

    Could you perhaps use something like:

    Please Login or Register  to view this content.

    worth adding perhaps that your time values are actually stored as hh:mm rather than mm:ss

  5. #5
    Registered User
    Join Date
    02-02-2010
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Average data for 30 second intervals with different number of data points

    hello,

    you can do an extra column where we can write some kind of coding. for example I made a text field containing the hour, the minute and if the seconds are below 30 put 0, or 30 if the seconds >30. Here's the formula i used:

    =IF(SECOND(B2)<=30,CONCATENATE(HOUR(B2),MINUTE(B2),"00"),CONCATENATE(HOUR(B2),MINUTE(B2),"30"))

    Further you just make a pivot table that has the coding as columns and the average of the time as values

    Hope it makes sens.

  6. #6
    Registered User
    Join Date
    02-02-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Average data for 30 second intervals with different number of data points

    Thanks for responses so far, not got access to computer at moment so will try the suggestions tomorrow

  7. #7
    Registered User
    Join Date
    02-02-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Smile Re: Average data for 30 second intervals with different number of data points

    Quote Originally Posted by DonkeyOte View Post
    Could you perhaps use something like:

    Please Login or Register  to view this content.

    worth adding perhaps that your time values are actually stored as hh:mm rather than mm:ss
    Thanks for this it works perfectly! I must admit I'm no excel expert and I don't really understand how the formula works, if you had time to briefly explain the logic that would be great.

    With regards to the data being in hh:mm, it seem to automatically be detected like that when I export the txt file with the raw data into excel, I tried changing it to mm:ss in the custom format menu but then your formulas didn't work, it's probably easier to leave it so excel assumes its hh:mm.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Average data for 30 second intervals with different number of data points

    In terms of explanation.... hard to be concise I'm afraid so instead I'll be vague

    F2 onwards is used to ascertain the starting point in the data set of each 30 "minute" window

    This is done by taking the starting time value in $F$1 [I omitted the formula which would be a basic MIN] and adding to that 30 "minutes" for every row processed (less one) such that:

    row 1 would be the start time
    row 2 would the start time + 30 minutes
    row 3 would be the start time + 60 minutes
    and so on and so forth

    and counting how many records are less than that value and then adding one to the result
    given the date is sorted in ascending order that result tells us the row position of the first value within the current "window"

    Once that's done it's simply a case of determining the Average of the appropriate data points.

    This is done by creating a Range and applying AVERAGE to it - the Range being created via 2 INDEX calls... we know the starting point of both the current window and the next window (values in F) so the range is created using:

    Please Login or Register  to view this content.

    So if current window is say 10 and next window is say 17 and we're looking at Col B values this creates a range of:

    Please Login or Register  to view this content.

    Given we have the range we simply apply the AVERAGE to it.
    Last edited by DonkeyOte; 02-03-2010 at 07:39 AM.

  9. #9
    Registered User
    Join Date
    02-02-2010
    Location
    Birmingham, UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Average data for 30 second intervals with different number of data points

    Thanks, an elegant solution, not sure I would ever have got there myself!

    Thanks again this will save me a lot of time.

  10. #10
    Registered User
    Join Date
    04-19-2019
    Location
    Adrian, Michigan
    MS-Off Ver
    Office 365
    Posts
    1

    Re: Average data for 30 second intervals with different number of data points

    This is an old post so hopefully somebody still watches this?
    I have a similar problem but my time stamps include date and time - and the time interval is variable. As I need to correlate two temperatures, one was taken every 30 minutes - which I can convert to hourly levels, but the second with variable intervals, I need to standardize (average) the second temperature also to every hour. I attach example data.
    Attached Files Attached Files

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Average data for 30 second intervals with different number of data points

    yes, this is an old thread.

    However, Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original. Please start a new thread - See Forum rule #4

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: Average data for 30 second intervals with different number of data points

    deleted......
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1