Counting elements in a list

I have a long (approx. 4000 rows) list whose elements are in the form as follows:

{{x,y,z},a,b,c}


I want to count the number of elements c in the last column that are greater than a certain number d. How can I do it?

• Total@UnitStep[data[[All, -1]] - d]? Of course, Count is much nicer to read, but also much slower. To have something nice to read and fast, check out BoolEval (BoolCount) Commented Sep 21, 2018 at 14:29
• The direct route: Count[ data, { __, c_ /; c > d}] Commented Sep 21, 2018 at 14:32
• Cannot understand what the structure of your list is. Commented Sep 21, 2018 at 14:42
• @ΑλέξανδροςΖεγγ It contains a list and three numbers for each row. Commented Sep 21, 2018 at 14:54

Suppose your long list is named data, one approach can be

Select[data, Last[#] > d &] // Length


where d should have a preset value.

list = {{{x, y, z}, 1, 2, 3}, {{a, y, z}, 2, 2, 1}, {{v, c, a}, 9, 7, 2}};


Using Count

Count[list, x_ /; Last[x] > 1]


2

list = {{{x, y, z}, 1, 2, 3}, {{a, y, z}, 2, 2, 1}, {{v, c, a}, 9, 7, 2}};


Grabbing the @eldo's list and using SequenceCount:

SequenceCount[list, {s_ /; Last[s] > 1}]

(*2*)


Some variants:

list = {{{x, y, z}, 1, 2, 3}, {{a, y, z}, 2, 2, 1}, {{v, c, a}, 9, 7,
2}};


Counting:

True /. CountsBy[list, Last[#] > 1 &]
True /. GroupBy[list, Last@# > 1 &, Length]
Total[Last/*(# > 1 &)/*Boole /@ list]


All yield 2