3
$\begingroup$

Consider a data having the form

data={{P,4,3,2},{V,7,8,9,55},{P,19,3,4},{V,48,6,1,55}}

How to remove all rows with V and then to remove the first column, i.e., to get

dataprime={{4,3,2},{19,3,4}}
$\endgroup$
1
  • 4
    $\begingroup$ e.g. Cases[data, {Except[V], rest__} :> {rest}] $\endgroup$
    – C. E.
    Apr 22, 2019 at 17:54

4 Answers 4

4
$\begingroup$
DeleteCases[data, {V, ___}][[All, 2 ;;]]

{{4, 3, 2}, {19, 3, 4}}

$\endgroup$
2
$\begingroup$
data = {{P, 4, 3, 2}, {V, 7, 8, 9, 55}, {P, 19, 3, 4}, {V, 48, 6, 1, 55}};

Two other possibilities

Cases[data, {P, a__} :> {a}]

{{4, 3, 2}, {19, 3, 4}}

Rest @@@ SequenceSplit[data, {{V, __}}]

{{4, 3, 2}, {19, 3, 4}}

$\endgroup$
1
$\begingroup$
data = {{P, 4, 3, 2}, {V, 7, 8, 9, 55}, {P, 19, 3, 4}, {V, 48, 6, 1, 55}};

Using SequenceCases:

SequenceCases[data, {s : {P, __}} :> Rest@s]

(*{4, 3, 2}, {19, 3, 4}}*)

Or using ReplaceList:

ReplaceList[data, {___, s : {P, __}, ___} :> Rest@s]

(*{4, 3, 2}, {19, 3, 4}}*)
$\endgroup$
1
$\begingroup$

data = {{P, 4, 3, 2}, {V, 7, 8, 9, 55}, {P, 19, 3, 4}, {V, 48, 6, 1, 55}}

Using Select:

data // Select[First@# =!= V &] // Map[Rest]

Using Pick:

Rest /@ Pick[data, First@# =!= V & /@ data]

Result:

{{4, 3, 2}, {19, 3, 4}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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