Tag: indexing

54 votes
4 answers
2.4K views
Is there an R function for finding the index of an element in a vector?

In R, I have an element x and a vector v. I want to find the first index of an element in v that is equal to x

avatar
Basil
0 1 0 9
asked 07 September, 2021
68 votes
9 answers
461 views
How can I index a MATLAB array returned by a function without first assigning it to a local variable?

For example, if I want to read the middle value from magic(5), I can do so like this: M = magic(5); value = M

avatar
Rudy
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
2.3K views
How to get the last element of a list?

In Python, how do you get the last element of a list?

avatar
Margo
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
686 views
Finding the index of an item in a list

Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?

avatar
Chelsea
0 1 0 9
asked 07 September, 2021