I'd like to return a a boolean variable that tells me whether numbers in a list are mostly positive. For example:
a = {3,2,3,4,-1,-2,-5,3}
There are 5 positive values and 3 negative ones in list a. That is, 5/8 of the values (more than 50% of them) are positive. How do I get a boolean variable that tells me if this is true or not.
mostlyPos[a_?VectorQ] := (Count[a, _?Positive]/Length[a]) > 1/2;
$\endgroup$ – Bob Hanlon Dec 2 '19 at 16:55mostlyPos[a_?VectorQ] := Mean[Unitstep[a-1]]>1/2
(works only for vectors of integers). $\endgroup$ – Henrik Schumacher Dec 2 '19 at 18:50