$\begingroup$Can you please provide some example data or a procedure to generate simulated data.$\endgroup$
– s0rceSep 2 '15 at 2:23

2

$\begingroup$Don't do it that way - mutating a step at a time is... slow. Make a zero list of correct length. Populate the indices at o1 with o1. Fold Max over that. Use result to pull values. All are one-step operations, should handle millions of entries in a fraction of a second...$\endgroup$
– ciaoSep 2 '15 at 4:26

$\begingroup$@belisarius: you mean o1? Then yes - it's time steps, so unless we're back to the future... if you meant o2 - not sure what you mean, it's just data values from my read.$\endgroup$
– ciaoSep 2 '15 at 5:28

4 Answers
4

Now that OP has accepted an answer, implicitly making the results from it correct, here's a much faster method than the fastest there (as in 3x to nearly order of magnitude faster, depending on amount of missing points):

$\begingroup$@SquareOne: Glad you like it, give update a whirl - simpler, and much faster again in my quick tests...$\endgroup$
– ciaoSep 5 '15 at 22:31

$\begingroup$@Matvei Kruglyak :appreciate the accept, glad you find answer useful. I'd humbly ask however that you return accept to SquareOne - their answer is most educational, shows effort, and they were kind enough to mention mine so if a reader has performance as top priority, they'll see mine referenced. I mark my answers as wiki so I get no points, I'd rather a deserving new poster like SquareOne get them...$\endgroup$
– ciaoSep 6 '15 at 3:23

$\begingroup$Added the new faster solution to my timings. Nice ! Also I had to correct your previous timings because I forgot to include the beginning part of your code, sorry ;( However, it is only a little bit slower.$\endgroup$
– SquareOneSep 6 '15 at 10:14

$\begingroup$I did actually ask OP to accept your answer as performance is clearly the goal. You can mention my post for the detailed timings and comparison with other approaches.$\endgroup$
– SquareOneSep 6 '15 at 10:18

It is not clear what the OP exactly needs at the extremities of the new list: for example here do the values for time steps 1 and 2 have to be 0 or 2.2 ? Same question for time step 10 ? The different approaches below show some differences regarding to this, but they could be easily adapted.

Ciao has provided the fastest answer ! It's a very instructive answer as it shows how fast can be working with Part and list of indices ([[{i1,i2,...}]]) and to always deal as much as possible with integers (FoldList[Max,...]).

$\begingroup$I don't think any of these is are the fastest possible way, but seeing as OP code is broken (or question is underspecified), moot at this point...$\endgroup$
– ciaoSep 4 '15 at 22:15

$\begingroup$Innovative use of Join, MapThread, ConstantArray and Differences. I get it to be about an order of magnitude faster than the original loop method.$\endgroup$
– Jack LaVigneSep 4 '15 at 23:13

$\begingroup$If you have time, please add my answer to timings - curious of results on your hardware, it is much faster on mine...$\endgroup$
– ciaoSep 5 '15 at 5:43

$\begingroup$BTW, if you do re-test, might want to do it reflective of OP example - you have the opposite: OP keeps most of the data, you are dropping most of it - should change n1 to about 2500000 to mimic OP.... I'd venture the order of performance of the different solutions might get juggled if the OP example is followed$\endgroup$
– ciaoSep 5 '15 at 6:22

2

$\begingroup$The interesting question is why TimeSeries is so slow. Is this a bug? Does WRI care?$\endgroup$
– Rolf MertigSep 6 '15 at 7:30

$\begingroup$I don't think this produces what the OP is asking for. I think he is asking for a zero-order interpolation.$\endgroup$
– m_goldbergSep 2 '15 at 14:34

$\begingroup$@m_goldberg And I don´t think what you do think :) Who knows!$\endgroup$
– Dr. belisariusSep 2 '15 at 19:14

1

$\begingroup$@m_goldberg This answer substitues the previous valid non-zero value for zero values in v2 (a direct substitution of o2 values is used). I applied Matvei Kruglyak code to a short version of example data and it matched belisarius's result. I believe it answers the question correctly.$\endgroup$
– Jack LaVigneSep 2 '15 at 19:51

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.