I have a ragged list
ragged = {{a,b,c,d,e},{x,y,z}}
that I would like to trim (on the right) to be rectangular. The desired result is
{{a,b,c},{x,y,z}}
It seems like this should be a one-word operation but I can't find the one word. So far the best I can do is to PadRight with Null and then delete everything with a Null in it.
Transpose[
DeleteCases[
Transpose[
PadRight[
ragged,
Automatic,
Null
]
],
a_ /; MemberQ[a, Null]
]
]
This seems way too complicated for such a simple operation. What is the simplest way to do this?
Answer
You are looking for Take
. To then make the array rectangular, I would do something like this
Take[ragged, All, Min[Length /@ ragged] ]
Comments
Post a Comment