Re: Selecting Sub-lists After Split
- To: mathgroup at smc.vnet.net
- Subject: [mg77455] Re: Selecting Sub-lists After Split
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Sat, 9 Jun 2007 05:32:21 -0400 (EDT)
walk == Rest@NestList[# + Random[] - 1/2 &, 0, 1000]; signedRuns == Split[walk, #1 #2 > 0 &]; Length /@ signedRuns negativeRuns == Select[signedRuns, First[#] < 0 &]; Length /@ negativeRuns {12, 11, 2, 22, 1, 207, 2, 3, 78, 1, 202, 38, 66, 355} {12, 2, 1, 2, 78, 202, 66} I didn't let negativeRuns display, but I think that's what you wanted. Bobby On Fri, 08 Jun 2007 04:34:49 -0500, Gregory Lypny <gregory.lypny at videotron.ca> wrote: > Hello everyone, > > Suppose I have a list of real number called myList. I split it into > sub-lists of positive and negative numbers called myNewList by doing > this (there may be a more elegant way): > > myNewList == Split[myList, #1 #2 > 0 &] > > Now, how can I select all of the sub-lists of negative numbers from > myNewList? > > Any tips would be most appreciated. > > Regards, > > Gregory > > -- DrMajorBob at bigfoot.com