Re: Conditions with Statistical Functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg66154] Re: Conditions with Statistical Functions*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Mon, 1 May 2006 01:30:48 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <16568608.1146308002406.JavaMail.root@eastrmwml01.mgt.cox.net> <e31vb8$hgd$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Gregory Lypny wrote: > Yes, thanks Bob. But what about a matrix, where Mean operates column- > wise? Is there a compact statement where the mean will be calculated > over the values that exceed 100 in each column all in one shot? What > I've been doing is looping Select across the columns using Do and > applying Mean on each pass. I just thought there might be something > more efficient, if not more elegant. > > Regards, > > Greg > > On Sat, Apr 29, 2006, at 6:53 AM, Bob Hanlon wrote: > >> x={10,20,150,200,250}; >> >> Mean[Select[x,#>100&]] >> >> 200 >> >> >> Bob Hanlon >> > > Hi Gregory, You could use either one of the following expressions: In[1]:= lst = Table[Random[Integer, {0, 200}], {12}, {4}]; In[2]:= TableForm[lst] Out[2]//TableForm= 49 152 110 46 65 54 45 30 42 147 189 22 145 165 139 58 125 138 153 192 77 199 195 91 103 59 92 97 135 118 170 190 117 196 182 45 81 32 183 145 74 26 82 83 72 196 129 83 In[3]:= Mean /@ (Transpose[lst /. x_ /; x <= 100 -> 0] /. 0 -> Sequence[]) Out[3]= 1311 1450 527 {125, ----, ----, ---} 8 9 3 In[4]:= Mean /@ (Select[#1, #1 > 100 & ] & ) /@ Transpose[lst] Out[4]= 1311 1450 527 {125, ----, ----, ---} 8 9 3 Best regards, Jean-Marc