Suppose I have a matrix (nested list) with some missing elements in the bottom region:
m={{1,5},{2,6},{3},{4}};
m//TableForm
1 5
2 6
3
4
As you see, there are two missing elements at the position of m[[3,2]]
and m[[4,2]]
.
I want to specify the position of the bottom element in the 2nd column, i.e., I want to specify the position of the element just before the position of the missing data.
In this example, at the 2nd column, the bottom element is 6 and lies at m[[2,2]]
.
Thus, the answer should be m[[2,2]]
.
Suppose that I do not know both the bottom value (6, in this case) and how many rows are missing in the 2nd column (because my real data has very long column).
To achieve this, I tried to calculate the length of the 2nd column:
Length@m[[All,2]]
But, this does not work, because part 2 of the 3rd and 4th rows do not exist. Any ideas would be appreciated.
Flatten[m, {{2}, {1}}]
to do a "generalized transpose" and pick off your desired lengths from there. $\endgroup$