1
$\begingroup$
dataSample = {g[ f[{10009, 10007, 10003, 10005}, {0.22584052329594687`,

0.23987428669761543`, 0.26528870462640836`, 0.26899648538002935`}], {1, 5, 257}],

g[f[{10009, 10007, 10003, 10005, 10002, 10004}, {0.1407652340009867`,

0.14951240638759009`, 0.1653530820756171`, 0.16766412270637168`, 0.17874523988109475`,

0.1979599149483397`}], {1, 3, 85}], g[f[{10009, 10007, 10003, 10005, 10002, 10004},

{0.1407652340009867`, 0.14951240638759003`, 0.1653530820756171`,

0.16766412270637168`, 0.17874523988109475`, 0.1979599149483397`}], {1, 5, 588}], g[f[{10009,

10007, 10003, 10005, 10002, 10004}, {0.1407652340009867`, 0.14951240638759009`,

0.1653530820756171`, 0.16766412270637168`, 0.17874523988109475`,

0.19795991494833973`}], {1, 2, 339}]};

res = Flatten[ Transpose[({#[[1, 1]], Head[#] #[[1, 2]] & /@ (#[[2]] /@

Transpose[(#[[1]] /. f -> List)])} & @ #)] & /@ dataSample, 1]

(*
    {{10009,{0.225841,1.1292,58.041}},{10007,{0.239874,1.19937,61.6477}},{10003,{0.265289,1.32
644,68.1792}},{10005,{0.268996,1.34498,69.1321}},{10009,{0.140765,0.422296,11.965}},{10007
,{0.149512,0.448537,12.7086}},{10003,{0.165353,0.496059,14.055}},{10005,{0.167664,0.502992
,14.2515}},{10002,{0.178745,0.536236,15.1933}},{10004,{0.19796,0.59388,16.8266}},{10009,{0
.140765,0.703826,82.77}},{10007,{0.149512,0.747562,87.9133}},{10003,{0.165353,0.826765,97.
2276}},{10005,{0.167664,0.838321,98.5865}},{10002,{0.178745,0.893726,105.102}},{10004,{0.1
9796,0.9898,116.4}},{10009,{0.140765,0.28153,47.7194}},{10007,{0.149512,0.299025,50.6847}}
,{10003,{0.165353,0.330706,56.0547}},{10005,{0.167664,0.335328,56.8381}},{10002,{0.178745,
0.35749,60.5946}},{10004,{0.19796,0.39592,67.1084}}}
*)

the goal is clear, but the progress is not so good, Let's see a element's structure:

g[f[{10009, 10007, 10003, 10005}, {0.22584052329594687`, 0.23987428669761543`,

0.26528870462640836`, 0.26899648538002935`}], {1, 5, 257}]

Here {10009, 10007, 10003, 10005} is keyList

is {0.22584052329594687,0.23987428669761543,0.26528870462640836,0.26899648538002935} is valueList

{1,5,257} is some kind of weights.

My solution is a little ugly, any nice methods?

$\endgroup$
  • $\begingroup$ @Kuba Hi, Your answer is right, I see you've used the option of Thread twice in my two answers, thanks, It's very useful. $\endgroup$ – HyperGroups Jan 19 '15 at 8:35
  • $\begingroup$ It is very nice, thanks for you second quesiton, I was not aware about Thread 3rd arg untill you asked and I did some digging! $\endgroup$ – Kuba Jan 19 '15 at 11:04
3
$\begingroup$
Block[{
  f = Transpose[{##}] &,
  g = Function[{x, m}, MapAt[m # &, x, {;; , 2}]]
  },
 Join @@ dataSample
 ]

or even "nicer":

Block[{
  f = ## &,
  g = {#, Times @@@ Thread[{##2}, List, 1]}\[Transpose] &
  },
 Join @@ dataSample
 ]
{{10009,{0.225841,1.1292,58.041}},
 {10007,{0.239874,1.19937,61.6477}},
 <<37>>,
 {10008,{0.324194,0.324194,59.3275}},
 {10001,{0.371523,0.371523,67.9887}}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.