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

- JMP User Community
- :
- Discussions
- :
- How to remove a set of values from a matrix/vector?

- 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
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 10, 2019 12:52 PM
(1662 views)

Hi. I have a large vector (i.e. 1-D matrix) of values, from which I'd like to remove a subset of the values, where the subset contains a non-sequential set of values from the original vector. For example:

largevect = [1,2,3,4,5]

subset = [2,5]

desired result = [1,3,4]

I'm wondering if a simple command or set of commands exists that could do this in JSL? I could do this with a For Loop, but wondering if there's a more elegant or faster method?

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

Probably need more information to answer this well.

If you are doing set operations, see https://community.jmp.com/t5/Uncharted/JSL-Set-Operations/ba-p/39379 for a way to do this with associative arrays:

```
// this would be a little more natural using lists
// or associative arrays, but it is easy to make an
// associative array set from a matrix:
largevect = [20, 30, 40, 50, 10];
subset = [20, 50];
aaBigSet = Associative Array( largevect );
aaSmallSet = Associative Array( subset );
// remove the small set from the big set
aaBigSet << Remove( aaSmallSet );
// getkeys returns a list, make a matrix
result = Matrix( aaBigSet << getkeys );
// the original order is lost, but the set is correct
show(result); // [10, 30, 40];
```

It is unclear in your example if *subset* is a list of values, or the indexes to values. If it is the indexes, and you could generate the set of indexes to keep instead of the set to remove, then it is as simple as

```
largevect = [20, 30, 40, 50, 10];
keepers = [1,3,4];
desired result = largevect[ keepers ];
show(desiredResult); // [20, 40, 50];
```

Craige

2 REPLIES 2

Highlighted

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

Probably need more information to answer this well.

If you are doing set operations, see https://community.jmp.com/t5/Uncharted/JSL-Set-Operations/ba-p/39379 for a way to do this with associative arrays:

```
// this would be a little more natural using lists
// or associative arrays, but it is easy to make an
// associative array set from a matrix:
largevect = [20, 30, 40, 50, 10];
subset = [20, 50];
aaBigSet = Associative Array( largevect );
aaSmallSet = Associative Array( subset );
// remove the small set from the big set
aaBigSet << Remove( aaSmallSet );
// getkeys returns a list, make a matrix
result = Matrix( aaBigSet << getkeys );
// the original order is lost, but the set is correct
show(result); // [10, 30, 40];
```

It is unclear in your example if *subset* is a list of values, or the indexes to values. If it is the indexes, and you could generate the set of indexes to keep instead of the set to remove, then it is as simple as

```
largevect = [20, 30, 40, 50, 10];
keepers = [1,3,4];
desired result = largevect[ keepers ];
show(desiredResult); // [20, 40, 50];
```

Craige

Highlighted
##

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

Re: How to remove a set of values from a matrix/vector?

Thanks Craige.

Your first assumption was correct: I wish to remove the literal values of 2 and 5 from the vector containing 1,2,3,4,5. Another example to help clarify, I wish to remove this subset vector from largevect:

largevect = [12, 189, 3, 78, -2]

subset = [189, -2]

dsired result = [12, 3, 78]

I've not used AA's much, but I like this as a solution. Thanks for the help!

Article Labels

There are no labels assigned to this post.