+ Reply to Thread
Results 1 to 8 of 8

Averaging rows by irregular values in Column X

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2014
    Location
    Colorado, USA
    MS-Off Ver
    2010, 2013
    Posts
    7

    Averaging rows by irregular values in Column X

    I am working to align data files from various sources for a research project, and I am trying to convert all of the data files so that 1 row = 1 second so that they can be easily aligned.
    However, my different programs record data at irregular rates. For example the program that captured the data in my HK_Participant2 file samples very irregularly between 5 & 10 hz, while my Participant2_Trial3.simdata files record at a varying 8-10 hz.

    I am trying to figure out how I can create a macro that will take the average of the rows within each second (in column B in both of my Worksheets) and output it to a new worksheet, but I am new to this and in over my head here.


    Thanks
    Attached Files Attached Files

  2. #2
    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,048

    Re: Averaging rows by irregular values in Column X

    Hi, welcome to the forum

    Without adding a helper (which would make it MUCH simpler), try this ARRAY formula, copied down...
    =SUMPRODUCT(IF(ROUND($F$2:$F$326,5)=ROUND(F2,5),$C$2:$C$326))/SUMPRODUCT(COUNT(IF(ROUND($B$2:$B$326,5)=ROUND(B2,5),$B$2:$B$326,"")))
    If you want to only show the 1st instance of a series, use this from the SECOND row down (if you put it inthe 1st row, it will give an error)...
    =IF(ROUND(B2,5)=ROUND(B1,5),"",SUMPRODUCT(IF(ROUND($F$2:$F$326,5)=ROUND(F2,5),$C$2:$C$326))/SUMPRODUCT(COUNT(IF(ROUND($B$2:$B$326,5)=ROUND(B2,5),$B$2:$B$326,""))))

    However, if you are able to add a helper column, use this (I used D), then put this in D2...
    =ROUND(B2,5)
    and then put this in E2...
    =IF(D2=D1,"",AVERAGEIF($D$2:$D$326,D2,$C$2:$C$326))
    both copied down
    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

  3. #3
    Registered User
    Join Date
    12-04-2014
    Location
    Colorado, USA
    MS-Off Ver
    2010, 2013
    Posts
    7

    Re: Averaging rows by irregular values in Column X

    Hi FDibbins and thanks for the help!

    I added in the helper column, but using the Round function on time values was throwing things off (with conversion of base 10 numbers to time being somewhat convoluted). I changed it to an MROUND(B2,0.00001157407) to make it round to the whole second and it works great!

    Also, is there an easy way to go about condensing the rows and outputing to a new worksheet? Adding additional columns is less of an issue with my HK files but .simdata csv files have a large number of columns that I will need to get an average for.

    Thanks again!

  4. #4
    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,048

    Re: Averaging rows by irregular values in Column X

    So, you pretty much want a summary of a 2nd sheet?

  5. #5
    Registered User
    Join Date
    12-04-2014
    Location
    Colorado, USA
    MS-Off Ver
    2010, 2013
    Posts
    7

    Re: Averaging rows by irregular values in Column X

    Yes, I would pretty much like to get a summary sheet out at the end of it, with just the average values (and the corresponding timestamp). Right now I am working on a hacked together macro that kind of does this by simply filtering out the blank spots, but a summary sheet with just the average values would be ideal.

  6. #6
    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,048

    Re: Averaging rows by irregular values in Column X

    See if the attached is what you want? I added a new sheet for the extract
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-04-2014
    Location
    Colorado, USA
    MS-Off Ver
    2010, 2013
    Posts
    7

    Re: Averaging rows by irregular values in Column X

    Yes that is. Unfortunately, I already got something else in place for it that is less elegant but does the job. I will definitely use your attachment as a reference for the future

  8. #8
    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,048

    Re: Averaging rows by irregular values in Column X

    As long as you got where you wanted to be Glad I was able to help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Averaging values from common rows
    By topazsparrow in forum Excel General
    Replies: 3
    Last Post: 05-29-2012, 06:47 PM
  2. Converting single column into multiple rows with irregular data
    By longhornpete in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-18-2012, 10:27 AM
  3. Averaging values from rows with identical column
    By Broccoli in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-15-2012, 07:51 PM
  4. Averaging values and replacing rows
    By eila90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2010, 08:16 PM
  5. Averaging values in different rows
    By pittopitto in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-21-2007, 10:46 PM

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