BookmarkSubscribe
Choose Language Hide Translation Bar

## Loop and concatenate

Hi,

I need a data table which creates random values in a column and concatenates the rows vertically. So far the script overwrites the columns but I need the final data table with 5xn rows including random values.

``````n=0; // counter

dt = new table("Test", add rows (5), new column("Random", numeric, continuous, formula(random uniform(0,6))), new column("Incr", numeric, continuous));

startwork = Function( {},
dt << add rows (5);
:random << formula(random uniform(0,6));
:Incr << formula(n);

n+=1;
if(n<10, Schedule(5, startwork() );
,
Schedule( 0, 0)
););
startwork();``````

So far the script overwrites the columns but I need the final data table with 5xn rows including random values.

Thanks for any help

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Loop and concatenate

There isn't a need to reset the formulas for each scheduled event.  So try the code below, and I think it might be what you need

``````dt = new table("Test", new column("Random", numeric, continuous, formula(random uniform(0,6))), new column("Incr", numeric, continuous,
formula( If(mod(Row(),5)==0,x=floor(Row()/5)-1,x=floor(Row()/5));x))
);

n=0; // counter
startwork = Function( {},
dt << add rows (5);

n+=1;
if(n<10, Schedule(5, startwork() );
,
Schedule( 0, 0)
););
startwork();``````
Jim
2 REPLIES 2

## Re: Loop and concatenate

There isn't a need to reset the formulas for each scheduled event.  So try the code below, and I think it might be what you need

``````dt = new table("Test", new column("Random", numeric, continuous, formula(random uniform(0,6))), new column("Incr", numeric, continuous,
formula( If(mod(Row(),5)==0,x=floor(Row()/5)-1,x=floor(Row()/5));x))
);

n=0; // counter
startwork = Function( {},
dt << add rows (5);

n+=1;
if(n<10, Schedule(5, startwork() );
,
Schedule( 0, 0)
););
startwork();``````
Jim

## Re: Loop and concatenate

Thank you very much, this works fine!