Suppose I have a nested list where sublists have unequal length. How can I extract all values of the list at specific level ignoring errors if the value at that level doesn't exist. For example:
lst={{1,2},{a, b, c, d}, {e, f, g, h}, {i, g, k}, {l}} How can I extract the values at position 4 of each sublist and get {d,h}. No surprise that lst[[All,4]] returns an error, but I don't even know where to start. Any help would be appreciated! Thanks
lst=PadRight[#,4,Null]&/@lstand then dolst=Part[lst,All,4]. Then, you could get{d,h}by executing something likeCases[lst, Except[Null],1]. $\endgroup$PadRight[lst], (as long as none of the values you extract from the list are zero). $\endgroup$