3
$\begingroup$

Consider the data which has the form

data = {{x1,y1,z1},{x2,y2,z2,t2},{x3,y4,z4,t4},{x5,y5,z5},...}

How to remove the rows containing three elements from the data?

I.e., to obtain

dataprime = {{x2,y2,z2,t2},{x3,y4,z4,t4},...}
$\endgroup$
  • 1
    $\begingroup$ Maybe you ask for DeleteCases[data, _?(Length[#] == 3 &)]... $\endgroup$ – Henrik Schumacher Feb 26 '19 at 14:46
  • $\begingroup$ @HenrikSchumacher : sorry, already corrected this. $\endgroup$ – John Taylor Feb 26 '19 at 14:49
8
$\begingroup$

Any one of these would do:

Cases[data, Except[_?(Length[#] == 3 &)]]
DeleteCases[data, _?(Length[#] == 3 &)]

Select[data, Length[#] != 3 &]

Delete[data, Position[data, _?(Length[#] == 3 &)]]

data /. {_, _, _} -> Nothing
data /. {Repeated[_, {3}]} -> Nothing

They all return: {{x2, y2, z2, t2}, {x3, y4, z4, t4}}

$\endgroup$
5
$\begingroup$

Also

Pick[data, Unitize[-3 + Length /@ data], 1]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.