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
- :
- new column with initial data values

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

Highlighted

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

Oct 18, 2011 5:54 AM
(7775 views)

Hi

Does anyone know how to script the creation of a new column with initial data values?

Below is my best guess, but it doesn't work. Cannot find any help on "initial data values" in the scripting guide.

BR, Marianne

dt=current data table();

dt<<new column("Selected", character, initial data values(constant("YES")));

1 ACCEPTED SOLUTION

Accepted Solutions

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

You're close. This will work:

dt=current data table**()**;

dt << new column**(**"Selected", character, << set each value**(**"YES"**))**;

5 REPLIES 5

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

You're close. This will work:

dt=current data table**()**;

dt << new column**(**"Selected", character, << set each value**(**"YES"**))**;

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

new column with initial data values

Excellent, just what I needed

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

Re: new column with initial data values

Hi!

I have a similar but a little more complicated problem:

The initial value I try to set is a function of loop index.

Suppose I have 50 files to open. When open each file, I want to add a new column, and fill the new column with the file name of this file. The initial value is supposed to be a constant. But, when this function is used within a loop, the code seems stuck. It opens the first file, without filling the initial value, and stopped.

How should I make it work?

Thanks a lot.

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

Re: new column with initial data values

Maybe something like this?

```
NamesDefaultToHere(1);
// Make some tables, save and close them, but keep a list
n = 4;
fList = {};
for(t=1, t<=n, t++,
fName = "Table "||Char(t)||".jmp";
dt = NewTable(fName, NewColumn("Data", Formula(RandomInteger(10))));
dt << AddRows(20);
InsertInto(fList, fName);
Close(dt, Save("$DESKTOP/"||fName));
);
// Open the tables in the list and add the column
for(t=1, t<=NItems(fList), t++,
fName = fList[t];
dt = Open("$DESKTOP/"||fName);
colVals = {};
for(r=1, r<=NRow(dt), r++,
InsertInto(colVals, fName);
);
dt << NewColumn("File Name", Character, Values(colVals));
DeleteFile("$DESKTOP/"||fName);
);
```

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

Re: new column with initial data values

Ian_jmp:

Your idea works great! Thank you so much!

JMP_Learner