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
newbie_alex
Level III

adding prefix to Character column values in an efficient way

Hello,

I have a character column with an unknown number of different values.

 

I would like to add a string prefix to each value but I struggle with doing so in an efficient way without creating a new column and without a for loop because it is slow.

 

Example for a single value:

Value is "12"

new value should be "PREFIX 12"

 

Is there a way to do this with JMP 12?

 

Here is the code without the step to add the prefix:

Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:Age << Data Type( Character );
// Get the values of age into a vector
ageVals = dt:Age << getValues;
// do not know what to do here. would like to add a PREFIX without a for loop (which would be slow)
???
// Put the new values back into the column
dt:Age << setValues(ageVals);

 

Best regards,

Alex

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: adding prefix to Character column values in an efficient way

I believe the quickest way to do this would be

Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:Age << Data Type( Character );
for each row(
	dt:Age = "PREFIX " || dt:Age
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: adding prefix to Character column values in an efficient way

I believe the quickest way to do this would be

Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:Age << Data Type( Character );
for each row(
	dt:Age = "PREFIX " || dt:Age
);
Jim
newbie_alex
Level III

Re: adding prefix to Character column values in an efficient way

Thank you.

 

That is actually quicker than expected even for my big data set.

 

Would you please help me understand why this is quicker than a regular for loop?

txnelson
Super User

Re: adding prefix to Character column values in an efficient way

I suspect the reason this is faster, is because it is a function that has very specific actions, and therefore has been optimized.

Jim