Finding and averaging multiple rows

Hello,
I am having a little problem and was wondering if anyone had any ideas on how to best solve it. 
Here is the problem: 
- I have a large file 6000 rows by 2500 columns. 
- First I sort the file by columns 1 and 2
- then I find that various rows in these two columns (1 and 2) have duplicate values, sometimes only twice, but sometimes three or four, or five or up to 9 times.
- this duplication occurs in only the first two columns, but we don't know in which rows and we don't know how much duplication there is. The remaining columns, i.e. column 3 to column 2500, for the corresponding rows contain data.
- Programatically, I would like to find the duplicated rows by searching columns 1 and 2 and when I find them, average the respective data for these rows in columns 3 to 2500.
- So, once this is done I want to save the averaged data to file. In each row this file should have the name of colunm 1 and 2 and the averaged row values for columns 3 to 2500. So the file will have n rows by 2500 columns, where n will depend on how many duplicated rows there are in the original file.
I hope that this makes sense. I have outlined the problem in a simple example below:
In the example below we have two duplicates in rows 1 and 2 and four duplicates in rows 5 to 8.
Example input file: 
Col1 Col2 Col3 ... Col2500
3 4 0.2 ... 0.5
3 4 0.4 ... 0.8
8 5 0.1 ... 0.4
7 9 0.7 ... 0.9
2 8 0.1 ... 0.5 
2 8 0.5 ... 0.8
2 8 0.3 ... 0.2
2 8  0.6 ... 0.7
6 9 0.9 ... 0.1
So, based on the above example, the first two rows need averaging (two duplicates) as do rows 5 to 8 (four duplicates). The output file should look like this:
Col1 Col2 Col3 ... Col2500
3 4 0.3 ... 0.65
8 5 0.1 ... 0.4
7 9 0.7 ... 0.9
2 8 0.375 ... 0.55
6 9 0.9 ... 0.1
Solved!
Go to Solution.

Well, here's an initial crack at it. The premise behind this
solution is to not even bother with the sorting. Also, trying to read
the whole file at once just leads to memory problems. The approach
taken is to read the file in chunks (as lines) and then for each line
create a lookup key to see if that particular line has the same first
and second columns as one that we've previously encountered. A shift
register is used to keep track of the unique "keys".
This
is only an initial attempt and has known issues. Since a Build Array is
used to create the resulting output array the loop will slow down over
time, though it may slow down, speed up, and slow down as LabVIEW
performs internal memory management to allocate more memory for the
resultant array. On the large 6000 x 2500 array it took several minutes on my computer. I did this on LabVIEW 8.2, and I know that LabVIEW 8.6
has better memory management, so the performance will likely be
different. 
Attachments:
Averaging rows.vi ‏30 KB

Similar Messages

  • Adding and Deleting Multiple Rows or Columns

    How do you add or delete more than one row or column at a time.

    Robby! wrote:
    That's a great finding!
    I just wrote a feedback requesting a shortcut like this.
    It is a pity though that they desing it to work only if you select the header of the row/column. It should be enabled to work from within any cell in the table.
    Who wrote such an error ?
    These interesting shortcuts behave flawlessly even if the cursor was in D18 for instance.
    (a) I never saw them in the delivered resources.
    (b) they aren't responding to the OP's question which was about "Adding and Deleting Multiple Rows and Columns"
    Yvan KOENIG (from FRANCE vendredi 3 octobre 2008 18:39:01)

  • How to find and replace multiple cells at a time

    I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
    i.e. doing my own budget spreadsheet and coding all transactions with description and code

    Did you try the "Find/Replace" dialog box?:
    Then click the "Replace All" button in the bottom left.

  • Updating and deleting multiple rows

    Hi!
    I have a form on a table with report page where I can filter data through columns.
    1. Is it possible to create a button that will delete all the filtered data?
    2. Also, I would like to be able to update any column of the filtered dataset to a certain value (that needs to be input somehow). Is that possible?
    So far I can only update or delete one row at a time, which isn't useful as I sometimes need to change 100 rows at a time with the same value or delete them.
    When I use tabular form, I can't filter rows, but I can delete multiple rows...
    Also if there are similar examples, could you please send me a link; I can't seem to find any.
    I'm using Apex 4.2.2.
    Best Regards,
    Ivan

    Deleting multiple rows - [url https://forums.oracle.com/forums/thread.jspa?threadID=2159983]common question
    Best answered with Martin's example
    http://www.talkapex.com/2009/01/apex-report-with-checkboxes-advanced.html
    Depends how you filter your data. You could identify all your limiting variables, and reverse the where clause in a delete process.
    As for point 2, you can define a button that redirects to the page, and you can defined all the item values you like using the Action link.
    There is likely an example in the supplied package applications.
    Scott

  • Join tables and replicate (multiple rows)

    Hi,
    i have two tables TAB1 (A, B, C) and TAB2 (C, D)
    i want to join the tables and replicat such that the resultant table TAB3 has columns A, B, D
    select x.a, x.b, y.d from tab1 x join tab2 y on x.c=y.c where y.d=1;
    but the problem here is that the above command gives multiple rows and i need all those to be in the target table. When i am using SQLEXEC-QUERY in the mapping, only the first search result is being entered into the TAB3. Then i Found out that sqlexec will return only one value. But i need all the search results to be replicated.
    What alternatives are there and what GG recommend in such use case?
    Any helpful advice is much appreciated.
    thanks,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

    the problem to use SP to check every time before insert/update is that there will be around 15 tables not 2 and there will be lakhs of rows in each table, SP which checks every insert will cause a lot of overhead and lag. I cannot afford that.
    More over there will be around 60 values of D and or each value of D there will be Lakhs of rows associated in TAB1
    I need to set up different extract and replicat processes for each set of rows associated with each value of D
    for example the values of column D are 1-30
    for D=1 there are 1.5lakh rows in TAB1 and EXT1, REP1 for this set of rows
    D=2 => 2lakhs rows in TAB2 and EXT2, REP2 for this set of rows
    D=3 => 1lakhs rows in TAB2 and EXT3, REP3 for this set of rows...etc
    this is to ensure that if i want to stop replicating data associated with D=1(which i need to do) i can stop only REP1 and keep the rest of the data associated with D=2-30 in sync
    As far as materialized views are concerned, i need to do it with goldengate only
    Thanks

  • Averaging multiple rows in Numbers '09

    Hello all, my question is this:
    Ive got a table with several thousand rows, and two columns. Column A is an identifier, and column B is a number associated with that identifier. However, there are some duplicates in column A, that have different respective numbers in column B. I want to go through these rows and average all values given for a certain duplicated identifier, and return that in a separate column. An illustration to explain better:
    original table:
    A B
    b0003 4
    b0003 5
    b0003 4
    b0001 1
    b0002 2
    output that i want:
    A B
    b0003 4.333
    b0001 1
    b0002 2
    possible?

    I can get you pretty close with the following:
    C2=A2
    C3=IF(A3="","",IF(COUNTIF(A$2:A2,A3)=0,A3,"")) fill down
    D2=IF(C2="","",SUMIF(A,C2,B)/COUNTIF(A,C2)) fill down
    This is if your data starts in row 2. It does not tighten it all up so the numbers are all together, there will be gaps if there are duplicate identifiers. If you did it in a separate table you could hide the blank rows.
    Formula in column C determines if the identifier is duplicated in a row above. If so it leaves C blank. If not a duplicate it copies the identifier to C.
    Formula in D says "if there is an identifier in C then add up all the values in column B for that identifier and divide by the number of times the identifier appears in column A. Otherwise leave D blank.

  • Find and Replace multiple line PHP comment

    Greeting everyone!
    Hopefully this question is asked in the right place.
    I have about 300 php files that have multiple line PHP
    comment that start with /* and end with this */. I want to remove
    all the comments since I am trying to reduce the file size as much
    as possible. The comments are no longer needed and I have tried
    many different configureation in the dreamweaver find and replace,
    but for the life of me I cannot seem to get it to work. I even
    tried useing regular expressions, but the astrick * is a wild card
    the the code tags contain an astrick.
    Is it possible to do this in dreamweaver, or will I need to
    hand edit every page?
    Thank for help
    example

    I am not sure of the exact syntax but open the find replace
    function on a page and play with find syntax search feature from
    the drop down menu . If I am not mistaken you should be able to to
    search from the beginning of a comment tag to the end of one and
    grab whats in between. From the help file
    Use the Find And Replace dialog box to search for text or
    tags in a document, and to replace the found material with other
    text or tags.
    Select Edit > Find And Replace.
    In the Search pop‑up menu, select Specific Tag.
    Select a specific tag or [any tag] from the pop‑up menu
    next to the Search pop‑up menu, or type a tag name in the
    text box.
    (Optional.) Limit the search with one of the following tag
    modifiers:
    With Attribute Specifies an attribute that must be in the tag
    for it to match. You can specify a particular value for the
    attribute or select [any value].
    Without Attribute Selects an attribute that must not be in
    the tag for it to match. For example, select this option to search
    for all img tags with no alt attribute.
    Containing Specifies text or a tag that must be contained
    within the original tag for it to match. For example, in the code
    <b><font size="4">heading 1</font></b>, the
    font tag is contained within the b tag.
    Not Containing Specifies text or a tag that must not be
    contained within the original tag for it to match.
    Inside Tag Specifies a tag that the target tag must be
    contained in for it to match.
    Not Inside Tag Specifies a tag that the target tag must not
    be contained in for it to match.
    (Optional.) To limit the search further, click the Plus (+)
    button and repeat step 3.
    If you didn’t apply any tag modifiers in steps 3 and 4,
    then click the Minus (-) button to remove the tag modifiers
    pop‑up menu.
    If you want to perform an action when the tag is found (such
    as removing or replacing the tag), select the action from the
    Action pop‑up menu and, if applicable, specify any additional
    information necessary to perform the action.

  • How to find and delete matching row in ADF BC

    Hi,
    I have a table with simple fields and I have created the java class for this entity also
    Person
         - Person_Id (PK)
         - Person_NameI wanted to create an application module method to search for the entity that matches certain name
    but I cant find the code to do this.
    public class AppModuleImpl{
      public boolean deletePersonByName(String personName)
        EntityDefImpl personDef = PersonImpl.getDefinitionObject();
        //How to get all rows and find the matching name then delete the row
        return false;
    }Thanks
    Jdev 11.1.1.5

    Ramandeep Nanda wrote:
    getfilteredRows does that, you can iterate and delete the rows after filtering on any attribute in view object it does not have to be a primary key.Hi Ramandeep,
    I got the idea and I somehow was able to do what I want.
      public boolean deletePersonByName(String personName)
        PersonViewImpl personView = this.getPersonView();
        Row[] matchingRows = personView.getFilteredRows("PersonName", personName);
        if(matchingRows!=null)
          for(Row rowTemp : matchingRows)
            PersonViewRowImpl personRow = (PersonViewRowImpl) rowTemp;
            personRow.remove();
            try
              getDBTransaction().commit();
            }catch(JboException ex)
              throw ex;
        return true;
      }But somehow I got this idea, supposed I have this data
    PersonId          PersonName
    1               MANDER
    2               MANDERRY
    3               JERRYThe code getFilteredRows somehow only perform an 'exact' match but what if I want to delete both of the data
    with PersonName 'MANDER' above.
    My current code only removes the person with name 'MANDER' and not the 'MANDERRY'
    Thanks

  • How can I find and replace multiple words at once?

    I need to be able to find and replace words into queens English. For example, I need to replace all instances of "color" with "colour," "tire" with "tyre" etc.
    I'm new to scripting, so simple answers would be appreciated :)

    Hi hobs707,
    Please use the below code for your required output:
    Replace ("color", "colour")
    Replace("tire", "tyre")           
    //Replace("hobs707", "hobs007")     just copy and paste and edit the contents as your wish
    function Replace(input, output)
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.findWhat = input;
    app.changeTextPreferences.changeTo = output;
    app.activeDocument.changeText();
    If the above answer is correct please provide Correct Answers for me.
    Regards
    Beginner

  • How To: Find and replace multiple words in one Click ?

    I have an file with about 150 Pages where I want to replace a word about 500 time by one click.
    Find and Replace works but only with one word.
    How can I do it by one click ?

    You can't, not in Acrobat anyway.
    This is the kind of thing that should be done in the original file format,
    not in a PDF.

  • Finding and combining multiple itunes libraries

    I believe I have set up multiple itunes libraries that are located on different drives (the internal and an external). I'd like to find them and combine them into one place. Any help would be appreciated..
    macbook running OS X 10.9.4

    The .itl is simply a listing of what tracks you have selected for that library.  It does not include the music itself.  I have never imported another library so I don't know if the methods Niel outlines will actually move your music files into the same library folder or simply use them where they are. You can easily check by seeing if they have moved to the folder, or by get info on a track in iTunes and look at the information on where the actual file it uses is located.
    Read the links below on what actually makes up a complete library and why combining them involves merging multiple items.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391

  • Display only one row for distinct columns and with multiple rows their valu

    Hi,
    I have a table having some similar rows for some columns and multiple different rows for some other columns
    i.e
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    9825000111 01-jan-06 'a' 991543154 02-feb-06 d
    9825000111 01-jan-06 'a' 154845545 10-mar-06 a
    What i want is to display only one row for above distinct row along with multiple non distinct colums
    ie
    o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
    9825000111 01-jan-06 'a' 980515464 01-feb-06 c
    991543154 02-feb-06 d
    154845545 10-mar-06 a
    regards,
    Kumar

    Re: SQL Help

  • Call tp EP and sending multiple rows of records

    Hello friends,
    I am creating a screen and am sending back to EP an user ID.
    However I would like to send Multiple User-Ids.
    Below is the code of what AM I doing.
             str = userid.    " NOTE - I would like to send Multiple IDS.
             lv_value_label->set_string_struct_element( element = str
                                                        label_name = 'MAINTID' ).
           it_result_state-result_state = 'APPROVED'.
           APPEND it_result_state TO it_result_states.
           CALL METHOD eup_structure_factory=>pack_value_label_to_xml
             EXPORTING
               iv_value_label = lv_value_label
             IMPORTING
               ev_xml         = str.
           CALL FUNCTION 'EUP_STORE_BSP_OUTPUT_DATA'
             EXPORTING
               iv_process_id    = process_id
               iv_task_id       = task_id
               iv_output_value  = str
             TABLES
               it_result_states = it_result_states.

    Dear Ster,
    I think you are having all the user id's in an internal table.
    Why dont you loop your internal table and pass those values in the standard FM you represented ('EUP_STORE_BSP_OUTPUT_DATA').
    I'm not aware that, whether there is any Standard FM's to be used for sending multiple user ID's. Will check and let you know.
    Hope this will be helpful.
    Regards,
    Gokul.N

  • How to find and delete multiple overlapping cut contour paths?

    Help!
    Background: My job requires that I print vinyl cut letters and shapes. I do this by creating a cut contour path in illustrator with a spot color as a stroke, so that once printed, there will be instructions on the print showing where to cut and the cutter will recognize the marks.
    My problem is that, for some reason, the cutter is going back over the cut path a 2nd time, as if there is more than one cut contour path in the file. But looking at the eps file in Illustrator, I don't see any extra overlapping paths with another stroke. It just looks like there is one pink line so it's very frustrating to know that there are actually extra cut paths that the cutter is reading that I don't know about. Is there a way for me to either A) find all of the paths and turn off the spot color swatch on all of them and just apply it to the one I need or B) find all paths and delete overlapping ones that I don't need?
    Someone also suggested that I might be getting extra overlapping cut paths in different Layers(?) I'm just really not sure what to do or how to find these and weed them out. Any help would be appreciated. I am relatively new to Illustrator and haven't found it a very intuitive program to learn, but maybe I just need a lot more practice.
    Thank you!

    You need to rebuild the file, as there is no way to fix any overalapping or duplicate paths.
    I make a layer for every color of vinyl, and then drag the selection square to the proper color layer. When done you can use the pathfinder command to unite each layer, to get rid of duplicate shapes.
    You alwasy want to proof before you send to cut, by doing a command Y to view your work in outline mode.

  • Updating ROW and inserting multiple row

    Hello,
    I needed some help.
    Firstly, i have VO which has 2 EO, these 2 EO are linked with association.
    In my page, i have a table, which by default has one row, and few fields can be edited, on click of "Apply" i want to commit this data,
    but when i use " getOADBTransaction().commit();" it gives me primary key constraint error.
    Secondly, when i click on add row button, it adds new row with unique primary key, also copying few attributes from existing first row.
    So, now when i want to update this table, since this VO is based on 2 EO's which are linked , i can't insert completely since in second EO parent EO's primary key is not inserted.
    Please help.

    I created new VO.
    It is EO based.
    Again, Commit is not working.
    code is
    public void create_row()
    SplitAtsVOImpl svo = getSplitAtsVO1();
    Row row = svo.first();
    Row r = svo.createRow();
    for(int i =1;i<row.getAttributeCount();i++)
    {System.out.println(i+"          "+row.getAttribute(i));
               if(row.getAttribute(i)!=null&&i<27)
             r.setAttribute(i,row.getAttribute(i).toString());
    r.setAttribute("DispAssNum",""+r.getAttribute("AssetNum")+"-"+count);
    r.setAttribute("AtsAssetId",getOADBTransaction().getSequenceValue("ATS_ASSET_TBL_S").toString());
    System.out.println(r.getAttribute("AtsAssetId"));
    r.setNewRowState(Row.STATUS_INITIALIZED);
    //r.setAttribute("AtsAssetId1",(""+row.getAttribute("AtsAssetId")));
    System.out.println(svo.getRowCount());
    svo.insertRowAtRangeIndex(0,r);
    try
    getOADBTransaction().commit();
    catch(OAException e)
    System.out.println(e.toString());
    }

Maybe you are looking for

  • Help needed in select query

    Hi, I need to select the max time for the transaction using the below query. I'm able to get the o/p. Here the problem is I need to fetch the corrletorid (primary key) as well. if try to get that I'm getting the o/p like case2. I want the o/p to be l

  • How to activate Long Text of Order Header in IW31/32

    Hi Expert, I have one reqm. like want to upload Long Text in Order Header. I have used FM 'Create_Text', its working f9 i.e. creating Long Text for Order Header but not displaying it in IW32/33 transaction. Entry for Long Text is available in Table S

  • Problem during import of Adapative WS Model in 2004s SP09

    Hi, I try to import a Adaptive WS Model and I have this error in error log file: Caused by: com.sap.engine.services.webservices.jaxrpc.exceptions.WebserviceClientException: GenericServiceFactory initialization problem. Could not load web service mode

  • CUA for ABAP and JAVA Systems

    i have a AS-ABAP System and AS-JAVA system. Can i have a single CUA for AS-ABAP system and aS-JAVA system or i should have seperate CUA for ABAP and JAVA

  • Ipad4 camera roll pictures upload to icloud - Croped pictures reverssed

    i edited pictures in ipad4, only croped the pictures, nothing else, then save to camera roll. it looks good, and then i upload pictures to icloud or skydrive, but the pictures there changed back to original uncropped version. i then use snapseed to d