Subscribe Bookmark RSS Feed

new column with initial data values

MTOF

Community Trekker

Joined:

Jun 29, 2011

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
Solution

You're close.  This will work:

dt=current data table();

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

5 REPLIES
Solution

You're close.  This will work:

dt=current data table();

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

MTOF

Community Trekker

Joined:

Jun 29, 2011

Excellent, just what I needed

JMP_Learner

New Contributor

Joined:

Jun 16, 2017

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

Staff

Joined:

Jun 23, 2011

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

New Contributor

Joined:

Jun 16, 2017

Ian_jmp:

 

Your idea works great! Thank you so much!

 

JMP_Learner