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
riteshj
Level I

Help to concatenate 3 columns with labels rather than values

Hello, I wanted to check if anyone has a solution for concatenating 3 columns with the labels of those columns rather than the values? 

 

Thanks

Ritesh 

4 REPLIES 4
jthi
Super User

Re: Help to concatenate 3 columns with labels rather than values

Do you want the final column to have values or labels (or both)? One option I think could be to create associative array of each of those columns and then use the column value as key to get correct value and concatenate those.

-Jarmo
pauldeen
Level VI

Re: Help to concatenate 3 columns with labels rather than values

Do you want to create a new column with the name being the other 3 column names concantenated to each other? Like this:

New Table( "Untitled 3",
	Add Rows( 0 ),
	Compress File When Saved( 1 ),
	New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) )
);
NewColumnName = (Column(1)<<get name) || "-" || (Column(2)<<get name) || "-" || (Column(3)<<get name);
New Column( NewColumnName, Numeric, "Continuous", Format( "Best", 12 ) );
hogi
Level XII

Re: Help to concatenate 3 columns with labels rather than values

following @jthi's idea, it could be something like this:

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

:age << Value Labels( {12 = "very young",13 = "young",14= "mid", 15 = "elder", 16 = "old",17 = "eldest"} );

Mylabels= arg(:age << get value labels,1);
splitList=Transform Each({pair},MyLabels,EvalList({Arg(pair,1),Arg(pair,2)}));
ageLabels=Associative Array(splitList);

New column("new",Character, Set Each Value(:sex ||"_"|| ageLabels[:age]))

 

hogi
Level XII

Re: Help to concatenate 3 columns with labels rather than values

Alternatively, you could use Recode to get a column with the value labels - and then use this column.

hogi_0-1686160309399.png

but I fear, Recode doesn't have an option 

Recode Column(columnname, Replace values with value labels, ...)

so, if you want to automate the process, you have to retrieve the label replacement rule like in the example above and paste it into the Recode Column expression:

	dt << Recode Column(
		dt:age,
		Map Value(
			_rcOrig,
			{12, "very young", 13, "young", 14, "mid", 15, "elder", 16, "old", 17,"eldest"},
			Unmatched( _rcNow )
	...