I have a list of n dimensional vectors (n=3 in this example). I want to find the position of all vectors for which all elements other than the $i^{th}$ element are equal to some value (2 in this example) and the value of the $i^{th}$ element is not restricted. I've been using the following approach: Create a pattern test that, when applied to a vector (i) deletes the ith element, (ii) deletes duplicates from the remaining elements, and (iii) checks whether the remaining list of non-duplicates is equal to {2}
.
points = {{0, 1, 2}, {2, 4, 2}, {2, 1, 2}, {2, 3, 4}};
Position[points, _?(DeleteDuplicates[Delete[#, 2]] == {2} &),{1}]
This approach works, but in the process I see several of the following messages:
Part 2 of List does not exist
Just to make sure my pattern test function is working, I tried
(DeleteDuplicates[Delete[#, 2]] == {2} &) /@ points
(*{False, True, True, False}*)
The messages go away if I change my pattern test by including List
immediately after the underscore:
Position[points, _List?(DeleteDuplicates[Delete[#, 2]] == {2} &),{1}]
As I am already providing a level specification, why is the _List
necessary to avoid these messages? What is happening when _List
is not included?