I want the in-built function Count to count the elements in a list which are greater than a value.
Example:
Count[{1, 1, 2, 3}, (# > 1.5) &]
Why doesn't this work?
I want the in-built function Count to count the elements in a list which are greater than a value.
Example:
Count[{1, 1, 2, 3}, (# > 1.5) &]
Why doesn't this work?
Your second argument is a function instead of a pattern.
Count[{1, 1, 2, 3}, _?(# > 1.5 &)]
Select is quite close to Count by its functionality. However, it recognizes the pattern argument in the form given in the above question, that is, just #>1.5& as follows: Select[{1, 1, 2, 3}, (# > 1.5 &)] returns {2, 3}. What is the difference between these two cases?
– Alexei Boulbitch
Feb 09 '16 at 09:34
Count[{{1,2},3,4}, _Integer, 2]. This cannot be done with Select, that works only on level 1.
– Fred Simons
Feb 10 '16 at 09:18
@ symbol from the username you defeat the automatic notification. Use e.g. @FredSimons (all one word) or at least the first three letters, e.g. @Fred. The author of the post you comment under is notified automatically, so you don't actually need that here; the system may strip it if you use it in fact.
– Mr.Wizard
Feb 11 '16 at 09:09
In V10.0+ you can stick with functions:
CountsBy[{1, 1, 2, 3}, (# > 1.5) &][True]