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$ Commented 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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.