[Date Index]
[Thread Index]
[Author Index]
Re: Help on iteration
*To*: mathgroup at smc.vnet.net
*Subject*: [mg54981] Re: Help on iteration
*From*: bghiggins at ucdavis.edu
*Date*: Tue, 8 Mar 2005 05:04:50 -0500 (EST)
*References*: <d0gv5a$7lg$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Cliff, There is some ambiquity in the statement of your problem. The
14th element of the second sublist is "N" not Q. If the 14th element is
always the second last element of each sublist, then here is a solution
that makes use of a replacement rule
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, d d, tt, Date3}};
tt=0;
Let us define some function that extracts a value based on the date
mydatefunc[d_]:=Switch[d,Date1,zz1,Date2,zz2,Date3,zz3]
glist /. {x__, y_ /; y == 0, z_} :>
{x, (s - C) + mydatefunc[z], z}
{{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, d^2,
-C + s + zz3, Date3}}
If the 14th element is not the second last element of each sublist,
here is a solution using Map:
Map[If[Part[#, 14] == 0, ReplacePart[#, (s - C) +
mydatefunc[Last[#]], Length[#]], , #] &, glist]
Cheers,
Brian
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. (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.
>
> My actual case is a bit more complicated than this
> but if I can see how to do something like this I can
> probably figure out my problem. Thanks for any help.
>
> Cliff
Prev by Date:
**Re: Outputing a tabular function**
Next by Date:
**Re: Re: computing residues**
Previous by thread:
** Re: Help on iteration**
Next by thread:
**coloring only some substring**
| |