Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: Loop and concatenate

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2019 7:41 AM
(316 views)

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

Highlighted
Solution

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted
Solution

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Loop and concatenate

Thank you very much, this works fine!