- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
JSL multiple column comparison to a fix number using for loop, and generate a new column for output
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL multiple column comparison to a fix number using for loop, and generate a new column for out
Hello @Stokes ,
Welcome to the JSL Community. The community should be able to help you address your problem. However, for your future posts , may I suggest a small thing, when you post code , kindly insert using one of the following options shown below. This will help format the code and make it easier for community users to understand your code and help answer your questions.
Now that we have gotten that out of the way , lets see how to address your problem:
If I understand your question correctly -
1. How to compare columns in a data table against any parameter ?
2. Why does a column reference ( Col = Column(dt,i); ) not directly replace a column name (:Col1) in a function call ?
I will try to address these questions as best as I can - so please let me know if I dont address anything in my response .
Clear Globals(); Clear Log();
// Open Sample Data
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Acquire Column Names
ColNames = dt1 << Get Column Names("String");
// Define a searchword and look for it in column names
DesiredColsPos1 = list();
DesiredColsPos2 = List();
KeyWord1 = "age";
for(i = 1 , i <= N Cols(dt1), i++,
If(Contains(ColNames[i],KeyWord1),
Insert Into(DesiredColsPos1,i);
);
);
// Display Result
Show(DesiredColsPos1);
// Alternatively
for(i = 1 , i <= N Cols(dt1), i++,
Col = Column(dt1,i); // This gets a reference for the column
Show(Col);
ColName = Col << Get Name;
If(Contains(ColName,KeyWord1),
Insert Into(DesiredColsPos2,i);
);
);
// Display Result
Show(DesiredColsPos2);
Uday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL multiple column comparison to a fix number using for loop, and generate a new column for out
Hello @Stokes ,
Welcome to the JSL Community. The community should be able to help you address your problem. However, for your future posts , may I suggest a small thing, when you post code , kindly insert using one of the following options shown below. This will help format the code and make it easier for community users to understand your code and help answer your questions.
Now that we have gotten that out of the way , lets see how to address your problem:
If I understand your question correctly -
1. How to compare columns in a data table against any parameter ?
2. Why does a column reference ( Col = Column(dt,i); ) not directly replace a column name (:Col1) in a function call ?
I will try to address these questions as best as I can - so please let me know if I dont address anything in my response .
Clear Globals(); Clear Log();
// Open Sample Data
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Acquire Column Names
ColNames = dt1 << Get Column Names("String");
// Define a searchword and look for it in column names
DesiredColsPos1 = list();
DesiredColsPos2 = List();
KeyWord1 = "age";
for(i = 1 , i <= N Cols(dt1), i++,
If(Contains(ColNames[i],KeyWord1),
Insert Into(DesiredColsPos1,i);
);
);
// Display Result
Show(DesiredColsPos1);
// Alternatively
for(i = 1 , i <= N Cols(dt1), i++,
Col = Column(dt1,i); // This gets a reference for the column
Show(Col);
ColName = Col << Get Name;
If(Contains(ColName,KeyWord1),
Insert Into(DesiredColsPos2,i);
);
);
// Display Result
Show(DesiredColsPos2);
Uday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL multiple column comparison to a fix number using for loop, and generate a new column for out
//add all pictures into a summary table
directory = Pick Directory();
fileNames = Files In Directory( directory );
summary = New Table( "summary", New Column( "name", character ), New Column( "rows", numeric ) );
For( iFile = 1, iFile <= N Items( fileNames ), iFile++,
filename = fileNames[iFile];
If( Ends With( filename, ".JPG" ),
// dt = Open( directory || filename );
summary << addrows( 1 );
summary:name = filename;
//summary:rows = N Rows( dt );
// Close( dt, "nosave" );
);
);