BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
adnan019
New Contributor

Fill a column vertically from two different data table

Hi

I am new to JSL. I have to merge to columns vertically to a new column something like below. Any help is appreciated.

 

jmp.jpg

0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
uday_guntupalli
Community Trekker

Re: Fill a column vertically from two different data table

@adnan019 ,
     There are multiple ways to do this. I will show you a few: 

 

// Create Data  Set 1
dt = New Table("Character Data"); 
dt << New Column("CharacterSet",Character,Nominal,<< Set Values({"A","B","C"}));

// Create Data Set 2 
dt1 = New Table("Numerical Data"); 
dt1 << New Column("NumericalSet",Character,Nominal,<< Set Values({"1","2","3"})); 

// Approach -1 
dt2 = dt1 << Concatenate( dt); 
dt2 << New Column("ConcatenatedData",Character,Nominal,Formula(If(IsMissing(:CharacterSet),:NumericalSet,:CharacterSet)));

// Approach - 2 
ValsFromTable1 = dt:CharacterSet << Get Values; 
ValsFromTable2 = dt1:NumericalSet << Get Values; 
AllData = ValsFromTable1 || ValsFromTable2; 
dt3 = New Table ();
dt3 << New Column("ConcatenatedSet",Character,Nominal,<<Set Values(AllData)); 

 Note that I modeled the numerical data as character, this is to enable the concatenation 

Best
Uday

Re: Fill a column vertically from two different data table

Or interactively:

First make sure the data type is for both columns character (or at least the same), otherwise concatenation won't work.

  • Using tables menu, "stack" will do what you want. Select your two or whatever number of columns and drag them on the "Stack Column" role.
  • Deselect "Stack by Row" to have a true concatenation
  • May modify Data, Label, and output table name and press okImg1.JPG

    That's it. 

And of course in the Source Script of the table you find the JSL approach:

Data Table( "MyData" ) << Stack(
	columns( :Col 1, :Col 2 ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	Stack By Row( 0 )
)

I like the others from Uday, too. 

Best 

Martin

 

0 Kudos
4 REPLIES 4
Highlighted
uday_guntupalli
Community Trekker

Re: Fill a column vertically from two different data table

@adnan019 ,
     There are multiple ways to do this. I will show you a few: 

 

// Create Data  Set 1
dt = New Table("Character Data"); 
dt << New Column("CharacterSet",Character,Nominal,<< Set Values({"A","B","C"}));

// Create Data Set 2 
dt1 = New Table("Numerical Data"); 
dt1 << New Column("NumericalSet",Character,Nominal,<< Set Values({"1","2","3"})); 

// Approach -1 
dt2 = dt1 << Concatenate( dt); 
dt2 << New Column("ConcatenatedData",Character,Nominal,Formula(If(IsMissing(:CharacterSet),:NumericalSet,:CharacterSet)));

// Approach - 2 
ValsFromTable1 = dt:CharacterSet << Get Values; 
ValsFromTable2 = dt1:NumericalSet << Get Values; 
AllData = ValsFromTable1 || ValsFromTable2; 
dt3 = New Table ();
dt3 << New Column("ConcatenatedSet",Character,Nominal,<<Set Values(AllData)); 

 Note that I modeled the numerical data as character, this is to enable the concatenation 

Best
Uday

Re: Fill a column vertically from two different data table

Or interactively:

First make sure the data type is for both columns character (or at least the same), otherwise concatenation won't work.

  • Using tables menu, "stack" will do what you want. Select your two or whatever number of columns and drag them on the "Stack Column" role.
  • Deselect "Stack by Row" to have a true concatenation
  • May modify Data, Label, and output table name and press okImg1.JPG

    That's it. 

And of course in the Source Script of the table you find the JSL approach:

Data Table( "MyData" ) << Stack(
	columns( :Col 1, :Col 2 ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	Stack By Row( 0 )
)

I like the others from Uday, too. 

Best 

Martin

 

0 Kudos
adnan019
New Contributor

Re: Fill a column vertically from two different data table

Thanks Martin. Interactively that is also helpful.

0 Kudos
adnan019
New Contributor

Re: Fill a column vertically from two different data table

Thanks. The || sign worked for me. 

0 Kudos