BookmarkSubscribeSubscribe to RSS Feed

Issue Making a For Loop

Seddod

New Contributor

Joined:

Jun 10, 2018

Hey,

 

I am trying to run a for loop to categorize several columns of data. Out of the 3 or 4 columns, the column with the highest value dictates a category for that entire row. I tried using this formula in a new column to no avail. For reference I am using a subset of data that I later saved as it's own individual file. 

 

For( i = 1, i < N Row( :Linked Subset ), i++, If( :Linked Subset[i][5] > :Linked Subset[i][3], :Label = "Hormone", If( :Linked Subset[i][4] > :Linked Subset[i][3] & :Linked Subset[i][6] > :Linked Subset[i][3], :Label = "ImmunoChemo", If( :Linked Subset[i][4] > :Linked Subset[i][3], :Label = "Chemo", If( :Linked Subset[i][6] > :Linked Subset[i][3], :Label = "Immuno", :Label = "None" ) ) ) ) )

 

I then tried running this script instead

 

 

dt = Open( "~/One Drive/Work/Research/Exported CSV/Subset.jmp" );

 

 

For( i = 1, i < N Row( :Linked Subset ), i++,

If( :Linked Subset[i][5] > :Linked Subset[i][3],

:Label = "Hormone",

If( :Linked Subset[i][4] > :Linked Subset[i][3] & :Linked Subset[i][6] > :Linked Subset[i][3],

:Label = "ImmunoChemo",

If( :Linked Subset[i][4] > :Linked Subset[i][3],

:Label = "Chemo",

If( :Linked Subset[i][6] > :Linked Subset[i][3],

:Label = "Immuno",

:Label = "None"

 

 

 

Any help as to why the script or formula isnt working is much appreciated. I admit, I was a bit lost when trying to write the script, so I think it is a bit far off from what it should be. I linked the file but I had to remove the first column of the data table for privacy issues.

 

Thanks

2 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

JMP is getting confused because you are using a column name reference (:Linked Subset) as a table variable.  Also you can clean up your if statements using only one IF.  I'm not sure if this is exactly what you want but it might give you some hints to get you closer to your goal.

dt = Open( "~/One Drive/Work/Research/Exported CSV/Subset.jmp" );

For( i = 1, i < N Row( dt ), i++, 
	If(dt[i][5] > dt[i][3], 
			:Label = "Hormone", 
		dt[i][4] > dt[i][3] & dt[i][6] > dt[i][3], 
			:Label = "ImmunoChemo", 
		dt[i][4] > dt[i][3], 
			:Label = "Chemo", 
		dt[i][6] > dt[i][3], 
			:Label = "Immuno", 
		:Label = "None"
	);
);

 

Seddod

New Contributor

Joined:

Jun 10, 2018

Thanks for clarifying! I tried replacing (:Linked subset) with (dt) in the formula but it did not output any categories for the designated column. I also tried your cleaned up version but it still did not work. Any ideas why there is still an issue with the formula?

 

 

Thanks for all the help.