MathGroup Archive 2005

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

Search the Archive

Re: Help on iteration

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54962] Re: Help on iteration
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 8 Mar 2005 05:03:48 -0500 (EST)
  • References: <d0gv5a$7lg$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Clifford Martin wrote:
> I've got a simple problem I can't seem to get right.
> Here is a sample set of data
> 
> glist={{a,b,c,d,e,f,g,h,l,m,n,o,p,q,Date1},
> {a,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,Date2},
> {a,R,s,t,u,v,X,Y,z,aa,bbb,cc,dd,tt,Date3}};
> 
> What I want to do is look at the 14th element in each
> sublist. 
You get this by: glist[[All,14]]

(For example in the above example data that
> would be values q, Q and tt). If any value is equal to
> zero (in my example lets say that tt =0) I want to
> 1.Check the date.
>  2.Pull a value associated with that date ,lets call
> it zzz. (that I've entered somewhere else and made a
> variable).
>   3. Calculate a new value for tt (non zero) using a
> calculation such as (s-C)+zzz.
>   4. Replace the value of tt(that was zero) with the
> new calculated value.
> 5. I want to do this for every list in my data set.

If I understand correctly, we want to check the 14th element in each 
sublist and if it is zero, to replace it by a function of the last 
element. Say we define a function fun that takes a sublist, checks 
element 14 and if zero, replaces it by a new value that depends on the 
last element:

fun[x0_];=Module[{x=x0},
    If[x[[14]]===0,x[[14]]= 2 Last[x]];
    x
]

glist= fun /@ glist
or without abbreviations:
glist= Map[fun,glist]

have fun, Daniel


  • Prev by Date: Re: Setting the ResultFormat in a ASP.NET WebApplication.
  • Next by Date: Re: Outputing a tabular function
  • Previous by thread: Re: Help on iteration
  • Next by thread: Re: Help on iteration