2
$\begingroup$
Range[1, 101, 1]

I have a list. Now I have to change some of the element position,
say 2 element position should come after 26, 27 element position should come after 51,
52 element position should come after 78, 77 element position should come after 101, How to do this? Actually, I have a huge amount of data, If I go about doing it manually it will be cumbersome and prone to error.

seems like it is not working for this data set

{0.,-0.00381335,-0.0000178914,-0.0000646514,-0.000137974,-0.000235554,-0.000355084,-0.000494261,-0.000650778,-0.000822331,-0.00100662,-0.00120133,-0.00140418,-0.00161285,-0.00182505,-0.00203848,-0.00225085,-0.00245987,-0.00266324,-0.00285868,-0.00304391,-0.00321664,-0.0033746,-0.00351552,-0.00363713,-0.00373716,0.00904689,-0.00386364,-0.00388539,-0.00387617,-0.00383354,-0.00375508,-0.00363836,-0.00348096,-0.00328047,-0.00303448,-0.00274058,-0.00239636,-0.00199943,-0.00154739,-0.00103784,-0.000468398,0.000163335,0.000859749,0.00162323,0.00245618,0.00336099,0.00434005,0.00539576,0.00653053,0.00774676,0.0646106,0.0104379,0.0119131,0.0134704,0.0151079,0.0168234,0.0186149,0.0204805,0.0224181,0.0244258,0.0265016,0.0286437,0.0308501,0.0331191,0.0354487,0.0378374,0.0402832,0.0427846,0.0453399,0.0479475,0.050606,0.0533137,0.0560694,0.0588716,0.0617191,0.144487,0.067547,0.0705232,0.0735364,0.0765838,0.0796625,0.0827698,0.0859033,0.0890604,0.0922387,0.095436,0.0986502,0.101879,0.105121,0.108373,0.111635,0.114905,0.118181,0.121462,0.124746,0.128034,0.131323,0.134614,0.137905,0.141196}

I am trying the same thing.

$\endgroup$
1
$\begingroup$
pos = Range[2, 101, 25];

ClearAll[f]
f = Fold[Insert[#, ##&@@ #2] &, Delete[#, List /@ pos], Transpose[{#[[pos]], pos + 24}]] &;
f@Range[101]

{1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 2, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 27, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 52, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 77}

Update: Using the example list in OP:

lst = {0., -0.00381335, -0.0000178914, -0.0000646514, -0.000137974,
 -0.000235554, -0.000355084, -0.000494261, -0.000650778, -0.000822331,
 -0.00100662, -0.00120133, -0.00140418, -0.00161285, -0.00182505,
 -0.00203848, -0.00225085, -0.00245987, -0.00266324, -0.00285868, 
 -0.00304391, -0.00321664, -0.0033746, -0.00351552, -0.00363713,  -0.00373716, 
  0.00904689, -0.00386364, -0.00388539, -0.00387617, -0.00383354, 
 -0.00375508, -0.00363836, -0.00348096, -0.00328047, -0.00303448, 
 -0.00274058, -0.00239636, -0.00199943, -0.00154739, -0.00103784, 
 -0.000468398, 0.000163335, 0.000859749, 0.00162323, 0.00245618, 
  0.00336099, 0.00434005, 0.00539576, 0.00653053, 0.00774676, 
  0.0646106, 0.0104379, 0.0119131, 0.0134704, 0.0151079, 0.0168234, 
  0.0186149, 0.0204805, 0.0224181, 0.0244258, 0.0265016, 0.0286437, 
  0.0308501, 0.0331191, 0.0354487, 0.0378374, 0.0402832, 0.0427846, 
  0.0453399, 0.0479475, 0.050606, 0.0533137, 0.0560694, 0.0588716, 
  0.0617191, 0.144487, 0.067547, 0.0705232, 0.0735364, 0.0765838, 
  0.0796625, 0.0827698, 0.0859033, 0.0890604, 0.0922387, 0.095436, 
  0.0986502, 0.101879, 0.105121, 0.108373, 0.111635, 0.114905, 
  0.118181, 0.121462, 0.124746, 0.128034, 0.131323, 0.134614, 
  0.137905, 0.141196};

lst2 = MapAt[Style[#, Red] &, lst, List /@ pos]

enter image description here

f @ lst2

enter image description here

Flatten @ Position[f @ lst2, _Style]

{26, 51, 76, 101}

$\endgroup$
  • $\begingroup$ Seems like I having trouble for doing the same thing for the dataset I have uploaded in the questions $\endgroup$ – acoustics Dec 24 '18 at 11:03
  • 1
    $\begingroup$ @acoustics, try f on your posted dataset. $\endgroup$ – kglr Dec 24 '18 at 11:07
  • $\begingroup$ I tried your suggestions , but not working $\endgroup$ – acoustics Dec 24 '18 at 11:17

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.