cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar

Find a column whose name needs a string from another column

I am trying to use a value from a column named "Freq " and find another column . I get an error Invalid Row

The column I am looking for is available. The column Freq is numeric. Is that the issue? 

For example the value in a row of the column Freq is 200 then I am looking for the value in IDynatTsense__200__65 . 

Code:

HashFreqval = Column( "Freq" );

IDyn = Column( "IDynatTsense__"||HashFreqval[]|| "__65" );

Error:

UnivariateTable_0-1726602124845.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Find a column whose name needs a string from another column

If your data is much more complicated and you don't need a formula, I would most likely just use For Each Row

Names Default To Here(1);

dt = Open("$DOWNLOADS/TestDataJunk.jmp");

dt << New Column("NewVal2", Numeric, Continuous);

For Each Row(dt,
	val = Column(dt, "HashFreq")[Row()];
	val_col = Eval Insert("Idyn_^val^_65");
	Column(dt, "NewVal2")[Row()] = Column(dt, val_col)[Row()];
);
-Jarmo

View solution in original post

4 REPLIES 4
hogi
Level XII

Re: Find a column whose name needs a string from another column

column[] returns the value of the current row().

The default value of row() is 0. To access the value of row 1, just adjust the pointer via row()=1;

 

New Table( "test",
	Add Rows( 1 ),
	New Column( "Freq",
	Character,
		Set Values( {"200"} )
	),
	New Column( "IDynatTsense__200__65",
		Set Values( [20] )
	)
);


HashFreqval = Column( "Freq" );
row()=1;
IDyn = Column( "IDynatTsense__"||HashFreqval[]|| "__65" );
jthi
Super User

Re: Find a column whose name needs a string from another column

Error is caused by what hogi wrote, column()[] (same as column()[row()]) is looking for a value of current row which by default is 0 in JMP, which is invalid row number (you can read about this from Iterate on Rows in a Table (jmp.com)).

 

How are you utilizing this code? Most likely this isn't the whole code you are using? You are looking value from "Freq" but which row and are you maybe looping them? Are you trying to get a value from IDynatTsense__200__65 (which row?) or just the reference? 

-Jarmo

Re: Find a column whose name needs a string from another column

Maybe my question is not very clear. I am attaching a simple example 

 

Depending on the value in the column HashFreq, I need to select data from either column Idyn_200_65 or Idyn_400_65. 

Once I can get that data , I can use a formula to calculate further. 

Names Default To Here( 1 );
dt1 = Open( "TestDataJunk.jmp" );
HashFreqval = Column( "HashFreq" );
IDyn = Column( "IDynatTsense__"||HashFreqval[]|| "__65" );
dt1 << New Column( "NewVal", Numeric, Continuous, Formula( IDyn[] ));

Thanks for your help!

jthi
Super User

Re: Find a column whose name needs a string from another column

If your data is much more complicated and you don't need a formula, I would most likely just use For Each Row

Names Default To Here(1);

dt = Open("$DOWNLOADS/TestDataJunk.jmp");

dt << New Column("NewVal2", Numeric, Continuous);

For Each Row(dt,
	val = Column(dt, "HashFreq")[Row()];
	val_col = Eval Insert("Idyn_^val^_65");
	Column(dt, "NewVal2")[Row()] = Column(dt, val_col)[Row()];
);
-Jarmo