1
$\begingroup$

If I have the following two lists:

list1= https://pastebin.com/zFin7kkB

list2= https://pastebin.com/8ymCin6d

where the first element of both list is the same. How can I replace the values in the second position in list1 with the values of the sencond position of list2 multiplied by 1.2, only when the values of the first position in list1 and list2 are greater than 74?. For example, I would like to obtain a list that would look like: {{40,0.0712996},{40.,0.0712996},{40.,0.0712996}......{74.0202,0.0594163*1.2},{74.0404,0.059451*1.2},{74.0606,2.5}....etc. where 0.0594163*1.2, 0.059451*1.2 and 0.0594857*1.2 are the values of list2 at the same temperature greater than 74 multiplied by 1.2.

Thank you in advanced,

$\endgroup$
2
$\begingroup$

Three of many possible ways:

1)

Select[list1,#[[1]]<=74&]~Join~(Select[list2,#[[1]]>74&]/.{x_,y_}:>{x,1.2y})

2)

Table[If[list1[[k,1]]<=74,list1[[k]],MapAt[1.2#&,list2[[k]],2]],{k,Length[list1]}]

3)

list3=Transpose[{list1[[All,1]],list1[[All,2]],list2[[All,2]]}];
list3/.{x_,y_,z_}:>{x,If[x<=74,y,1.2 z]}
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much Vitaliy Kaurov!. They both work great ! $\endgroup$ – John May 24 at 4:11
  • $\begingroup$ @John I added a method and corrected a typo in Method 2) above. $\endgroup$ – Vitaliy Kaurov May 24 at 4:20
0
$\begingroup$

Get the position of elements in list that are greater than or equal to 74:

positions=PositionIndex[UnitStep[dlist[[All,1]] - 74]][1];

Extract these positions from list2 and make the desired modification:

modified=Extract[dlist2,List/@positions].{{1,0},{0,1.2}};

Use ReplacePart to generate the desired output from list:

ReplacePart[dlist, Thread[positions-> modified]]

{{40, 0.0712996}, {40.0303, 0.0712996}, {40.1206, 0.0712996}, {40.2709, 0.0712996}, {40.4812, 0.0712996}, {40.7515, 0.0712996}, {41.0818, 0.0712996}, {41.4721, 0.0712996}, {41.9224, 0.0712996}, {42.4327, 0.0712996}, {43.003, 0.0712996}, {43.6333, 0.0712996}, {44.3236, 0.0712996}, {45.0739, 0.0712996}, {45.8842, 0.0712996}, {46.7545, 0.0712996}, {47.6848, 0.0712997}, {48.6751, 0.0712998}, {49.7254, 0.0712999}, {50.8357, 0.0713001}, {52.006, 0.0713005}, {53.2363, 0.0713013}, {54.5266, 0.0713027}, {55.8769, 0.0713055}, {57.2872, 0.0713108}, {58.7575, 0.0713215}, {60.2878, 0.0713431}, {61.8781, 0.0713877}, {63.5284, 0.0714818}, {65.2387, 0.0716832}, {67.009, 0.0721217}, {68.8393, 0.0730904}, {70.7296, 0.0752558}, {72.6799, 0.0801279}, {74.6902, 0.0727345}, {76.7605, 0.0779653}, {78.8908, 0.084852}, {81.0811, 0.0939294}, {83.3314, 0.105899}, {85.6417, 0.121673}, {88.012, 0.14242}, {90.4423, 0.169613}, {92.9326, 0.20505}, {95.4829, 0.250837}, {98.0932, 0.309269}, {100.764, 0.382531}, {103.494, 0.472162}, {106.284, 0.578142}, {109.134, 0.697711}, {112.045, 0.8242}, {115.015, 0.94674}, {118.045, 1.05203}, {121.136, 1.12888}, {124.286, 1.17383}, {127.496, 1.19332}, {130.767, 1.19897}, {134.097, 1.19992}, {137.487, 1.2}, {140.937, 1.2}, {144.448, 1.2}, {148.018, 1.2}, {151.648, 1.2}, {155.339, 1.2}, {159.089, 1.2}, {162.899, 1.2}, {166.77, 1.2}}

In the above, dlist and dlist1 are down-sampled versions of list and list1, respectively (sampled every 100th element)

| improve this answer | |
$\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.