cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
MTOF
Level III

new column with initial data values

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
pmroz
Super User

new column with initial data values

You're close.  This will work:

dt=current data table();

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

View solution in original post

6 REPLIES 6
pmroz
Super User

new column with initial data values

You're close.  This will work:

dt=current data table();

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

MTOF
Level III

new column with initial data values

Excellent, just what I needed

JMP_Learner
Level I

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.

ian_jmp
Level X

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);
);
JMP_Learner
Level I

Re: new column with initial data values

Ian_jmp:

 

Your idea works great! Thank you so much!

 

JMP_Learner

hogi
Level XII

Re: new column with initial data values