MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Request for help: working with multi-level lists


Try this:

<<Statistics`DescriptiveStatistics`

Mean[ Transpose[Select[list,#1[[1]]==1&]][[2]] ]

Select uses a pure function to choose those elements for which
element[[1]] ==1, Transpose transposes the list so that it is now is a
list of three lists, the 2nd of which is a list of the 2nd elements,
then [[2]] chooses just that list and Mean computes the average.
"<<Statistics`DescriptiveStatistics`" loads Mean.

Dave


KCConnolly wrote in message <6qp3mc$al3 at smc.vnet.net>...
>I have a list of 10 elements, each of which is a list of three elements
>(let's say in each case an integer, a real number, and a string). I am
>looking for the most elegant way to select those first-level elements
>(i.e., the lists) whose integer element is equal to a particular value
>(let's say "1"), and then to obtain the mean of the real number
>elements of the lists selected.  This seems as if it should be simple,
>but everything I try leads to Part specification errors.  Any help
>would be greatly appreciated.
>



  • Prev by Date: Re: linking c++ and mathematica
  • Next by Date: Problems with packages
  • Previous by thread: Re: Request for help: working with multi-level lists
  • Next by thread: Re: Request for help: working with multi-level lists