Choose, Lookup, and finding offset values

4.31K viewsFormulas and Functions
0

I’m wanting to find the n’th value in a list (specifically a vector in a matrix).
The obvious function would appear to be Choose – but this seems to require an explicit comma delimited list following the offset i.e. per the Sample:
[code:3c1nm1n6]result = choose(3,Lists::B1,Lists::B2,Lists::B3,Lists::B4,Lists::B5,Lists::B6,Lists::B7,Lists::B8,Lists::B9,Lists::B10)[/code:3c1nm1n6]
whereas this (which is what I need, since I don’t know in advance how many items may be in the category) fails:
[code:3c1nm1n6]bad = choose(3,Lists::B)[/code:3c1nm1n6]

On the other hand with Lookup I can have
[code:3c1nm1n6]result = lookup(3,Key List::B,Lists::B) [/code:3c1nm1n6]
(I don’t need to state the range explicitly as in the sample:
[code:3c1nm1n6]result = lookup(<foo>,Lists::B1 .. B10,Key List::B1 .. B10) [/code:3c1nm1n6])

But that requires me to create a dummy Key List with 1 – n as values for Items named 1 – n. Plus reversing the order of the Key List and the values List.

All of which seems very strange. What am I missing – and why doesn’t Choose do what I would expect?

Thanks

0

Thanks so much Mike. I did try using Select initially but didn’t find the magic operator # as applied to a Matrix name.

BTW – I don’t think the use of the # operator is in the documentation anywhere (not that I found). The use with a category name to return the position along the category is found in samples and seems to be fairly well known, but the use with a Matrix name in the way you show here is I think a well kept secret…

You are viewing 1 out of 3 answers, click here to view all answers.