Re: how to partition a list
- To: mathgroup at smc.vnet.net
- Subject: [mg117386] Re: how to partition a list
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Wed, 16 Mar 2011 06:51:39 -0500 (EST)
- References: <ilksc4$69u$1@smc.vnet.net> <201103141158.GAA07823@smc.vnet.net> <201103151103.GAA24699@smc.vnet.net>
It's probably not most efficient way, but what about doing something like this:
Module[{npos = 5, nestf, add = 5},
nestf[lst1_] :=
Append[Drop[lst1, lst1[[npos, 1]] + add],
Take[lst1, lst1[[npos, 1]] + add]];
Nest[nestf, Drop[data, 1], data[[1, 1]]]]
output:
{{{"T", "vs.", "Distance", "for", "part",
4}, {"Distance"}, {"T"}, {1}, {5}, {0, 300.006}, {5, 300.006}, {10,
300.006}, {15, 300.006}, {20, 300.006}}, {{"P", "vs.", "Distance",
"for", "part", 4}, {"Distance"}, {"P"}, {1}, {6}, {0,
1.00007}, {5, 1.00007}, {10, 1.00007}, {15, 1.00007}, {20,
1.00007}, {25, 1.00007}}, {{"CO2", "vs.", "Distance", "for",
"part", 4}, {"Distance"}, {"CO2"}, {1}, {7}, {0, 0.000326099}, {5,
0.000326099}, {10, 0.000326099}, {15, 0.000326099}, {20,
0.000326099}, {25, 0.000326099}, {30, 0.000326099}}}
Heike
On 15 Mar 2011, at 11:03, Ted Sariyski wrote:
> Hi,
> I have data with the following structure: the first element is the
> number of variables. For each variable follow:
> title,x_var,y_var,dummy,number of points, {points}. I want to extract
> data for each variable. Coming from Fortran I tend to make a Do-cycle,
> count for the current position and assign values one by one. Is there a
> better approach to this problem?
> Thanks,
> --Ted
>
>
> data={{3}, {"T", "vs.", "Distance", "for", "part", 4}, {"Distance"},
> {"T"}, {1}, {5}, {0, 300.006}, {5, 300.006}, {10, 300.006}, {15,
> 300.006}, {20, 300.006},
> {"P", vs.", "Distance", "for", "part", 4}, {"Distance"}, {"P"}, {1},
> {6}, {0, 1.00007}, {5, 1.00007}, {10, 1.00007}, {15, 1.00007}, {20,
> 1.00007}, {25, 1.00007},
> {"CO2","vs.", "Distance", "for", "part", 4}, {"Distance"}, {"CO2"}, {1},
> {7}, {0, 0.000326099}, {5, 0.000326099}, {10, 0.000326099}, {15,
> 0.000326099}, {20, 0.000326099}, {25, 0.000326099}, {30, 0.000326099}}
>
>
>
- Follow-Ups:
- how to plot 'carpet' of curves
- From: Ted Sariyski <tsariysk@craft-tech.com>
- how to plot 'carpet' of curves
- References:
- Re: Export strings to .pdf
- From: Yves Klett <yves.klett@googlemail.com>
- how to partition a list
- From: Ted Sariyski <tsariysk@craft-tech.com>
- Re: Export strings to .pdf