Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Issue Making a For Loop

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Issue Making a For Loop

Jun 14, 2018 4:45 AM
(310 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Issue Making a For Loop

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"
);
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Issue Making a For Loop

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.