LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  how to duplicate rows?

    Employee
    Posted 02-16-2009 09:32

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Lubanski

    Hi,

    How can I duplicate input rows in brain?

    I would like to get the following output
    x:string, count:int, id:int
    a,2,1
    a,2,2
    b,3,1
    b,3,2
    b,3,3

    out of the following input (the count column says how many output rows should be created out of the original one):
    x:string, count:int
    a,2
    b,3<br><br>Post edited by: Lubanski, at: 2009/02/16 10:38


  • 2.  RE: how to duplicate rows?

    Employee
    Posted 02-16-2009 09:43

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: johnpelz

    You basically need to loop on your "count" input column and use the "do output" statement to write a record to the output for each loop iteration.

    See the attached example.
    Attachments:
    Duplicate_Rows.brg


  • 3.  RE: how to duplicate rows?

    Employee
    Posted 02-16-2009 10:06

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Lubanski

    many thanks!

    tried several emits, but with no luck.


  • 4.  RE: how to duplicate rows?

    Employee
    Posted 10-10-2010 06:22

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dwong80

    I have a similar question about duplicate rows.

    I want to duplicate results (without writing it to the database) a certain number of times (example below = 3 times) and add a counter to the end of another column.

    Example:
    • 1111, A
    • 2222, B

    Desired Result (for example):
    • 1111, A1
    • 1111, A2
    • 1111, A3
    • 2222, B1
    • 2222, B2
    • 2222, B3

    I want to then use the desire result set for further graph processing.

    What's the best way to do this?


  • 5.  RE: how to duplicate rows?

    Employee
    Posted 10-11-2010 08:13

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: timonk

    If you download and take a look at the graph posted by johnpelz, the results it produces appear to be kind of duplication you want. All that you would be required to add is a bit of brainscript to perhaps convert the value of your "count" field to a string, then merge it with the field you have with values "A" or "B".

    Something like
    emit strcat('x', str('count')) as FOO
    (to use John's example)

    If you wanted to add a bit more useability to the node doin the duplication, you could create either a node parameter, or a graph level parameter to take the place of the 'count' value, so the loop would go from 'i' until it hit your chosen value.