cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Pertussic
Level II

Indexing Characters?

Is there a way to use an index argument with characters like one can do with numerals?  For example, while  1::5 would yield {1,2,3,4,5}, is there an efficient method to do X8::Y2 or am I stuck having to write out {"X8", "X9", "Y0", "Y1", Y2"}?

Thanks!

----------
It’s not enough to know the results. You have to know what they mean.
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Indexing Characters?

Looping should be fairly efficient way of doing that and if you have to do it often you could convert it into a function. Below is very simple version of the function

Names Default To Here(1);

idx_char = function({letter, start = 1, end = 8}, {Default Local},
	letter_list = {};
	For(i = start, i <= end, i++,
		Insert Into(letter_list, letter || char(i))
	);
	return(letter_list);
);

idx_char("Y", 1, 5); //{"Y1", "Y2", "Y3", "Y4", "Y5"}
-Jarmo

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Indexing Characters?

Here is one example of using a For Each to deal with a lists values without having to use an index.  I am not sure it adds any solution for you, but it kind of gets you going in a possible solution.

names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");

for each( {colname,i}, dt<<get column names(string),
	show(i,colname)
)
Jim
Pertussic
Level II

Re: Indexing Characters?

Actually, this is a potential alternative for another piece of code I'm working on.  If there was an "Accept as Solution but to a Different Problem," I'd press it.

Thanks!

----------
It’s not enough to know the results. You have to know what they mean.
jthi
Super User

Re: Indexing Characters?

Looping should be fairly efficient way of doing that and if you have to do it often you could convert it into a function. Below is very simple version of the function

Names Default To Here(1);

idx_char = function({letter, start = 1, end = 8}, {Default Local},
	letter_list = {};
	For(i = start, i <= end, i++,
		Insert Into(letter_list, letter || char(i))
	);
	return(letter_list);
);

idx_char("Y", 1, 5); //{"Y1", "Y2", "Y3", "Y4", "Y5"}
-Jarmo
Pertussic
Level II

Re: Indexing Characters?

Thank you.  This will work nicely.

----------
It’s not enough to know the results. You have to know what they mean.