MathGroup Archive 2003

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

Search the Archive

Re: Substitution in BinLists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41454] Re: Substitution in BinLists
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Tue, 20 May 2003 03:29:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/19/03 at 5:14 AM, markb at ravel.zoology.wisc.edu (Mark E. Berres)
wrote:

>Hi, I'm trying to substitute a zero (0) for bins that are empty when
>using BinLists:

>In[192]:= <<Statistics`DataManipulation` 
>In[193]:= a={1,2,3,4,10};
>In[194]:= BinLists[a,{0,10,1}]

>Out[194]:= {{1},{2},{3},{4},{},{},{},{},{},{10}}
>
>What I would like output is {1,2,3,4,0,0,0,0,0,10}. 

Try

If[Length@#>0, First@#, 0]&/@BinLists[a, {0, 10, 1}]

Note, while this does what you asked the result may not be what you really want.

BinLists is intended to provide a list of lists. Each sublist is a list of the elements from the original list that fall between the specified endpoints. A key point is, the output of BinLists contains exactly the same elements the orginal list contained. By inserting 0's for empty lists you've no way to distinguish between a 0 that was an element of the original list and a 0 you inserted. It is very hard to imagine why you would wnat data elements of a list comingled with 0's representing the absence of data elements in a given interval. In addition, the code I provided will not retain all of the elements of the original list in general.

Suppose instead of a step size of 1 you wanted a step size of 2. Then the output of BinLists would be
{{1, 2}, {3, 4}, {}, {}, {10}} and the output of my solution to your request would be {1, 3, 0, 0, 10}.

If your goal is to have flat list with the *number* of elements between endpoints you should be using BinCounts not BinLists



  • Prev by Date: Magic number 23
  • Next by Date: RE: Errors in Copying and Pasting Heads of Expressions
  • Previous by thread: Re: Substitution in BinLists
  • Next by thread: new user installation problem