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
- :
- How to find locations in the list that satisfy some condition?

Topic Options

- Start Article
- 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

Feb 17, 2017 4:41 PM
(1811 views)

There is a way to find locations in the list for specific item.

For instance:

Loc([1 0 1 0 1 0]) = [1, 3, 5]; Loc({"A", 2, 3, 2, 5, 2, 4, [1 5]}, 2) = [2, 4, 6]; Loc({"A", 2, 3, 2, 5, 2, 4, [1 5]}, [1 5]) = [8];

Similarly to that, I want to find all locations in the list, where values are less (or greater) than a certan number.

Something alont the lines:

myList={3,5,2,6,9,13,17}; Loc(myList<6) = [1,2,3];

Is there a simple way of doing that?

1 ACCEPTED SOLUTION

Accepted Solutions

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

As far as I know, there isn't such a function, however, here is a function that I built that does what you want:

```
a = {1, 3, 3, 2, 4, 2};
myLoc = Function( {list, x, comparison},
result = [];
For( i = 1, i <= N Items( list ), i++,
Eval(
Parse(
"If(list[i] " || Eval( comparison ) || " " || Char( Eval( x ) ) || ",result = result |/ i);"
)
)
);
result;
);
test = myloc( a, 2, ">" );
```

Jim

1 REPLY 1

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

As far as I know, there isn't such a function, however, here is a function that I built that does what you want:

```
a = {1, 3, 3, 2, 4, 2};
myLoc = Function( {list, x, comparison},
result = [];
For( i = 1, i <= N Items( list ), i++,
Eval(
Parse(
"If(list[i] " || Eval( comparison ) || " " || Char( Eval( x ) ) || ",result = result |/ i);"
)
)
);
result;
);
test = myloc( a, 2, ">" );
```

Jim