Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a list of {date,value} pairs so if you <a href="http://reference.wolfram.com/mathematica/ref/Transpose.html" rel="nofollow noreferrer">Transpose</a> that you'll have a list of two lists -- the first a list of dates and the second a list of corresponding values. You can then take the <a href="http://reference.wolfram.com/mathematica/ref/Differences.html" rel="nofollow noreferrer">Differences</a> of the values, <a href="http://reference.wolfram.com/mathematica/ref/Prepend.html" rel="nofollow noreferrer">Prepend</a> 0, and then Transpose again to get back to a list of pairs.</p> <p>In code,</p> <pre><code>data = {{{1971,1,31,0,0,0}, 1.0118}, {{1971,2,28,0,0,0}, 1.0075}, {{2010,5,31,0,0,0}, 1.0403}} {dates, values} = Transpose[data]; diffs = Prepend[Differences[values], 0]; answer = Transpose[{dates, diffs}] </code></pre> <p>which returns:</p> <pre><code>{{{1971,1,31,0,0,0}, 0}, {{1971,2,28,0,0,0}, -0.0043}, {{2010,5,31,0,0,0}, 0.0328}} </code></pre> <p>To wrap that up into a single function, with thanks to <a href="https://stackoverflow.com/users/212538/janus">Janus</a> for the idea:</p> <pre><code>taildiffs[data_]:= Transpose @ {#1, Prepend[Differences[#2], 0]}&amp; @@ Transpose@data </code></pre> <p>Note that the <code>... #1 ... #2 ... &amp;</code> construct is a pure function:</p> <p><a href="http://reference.wolfram.com/mathematica/ref/Function.html" rel="nofollow noreferrer">http://reference.wolfram.com/mathematica/ref/Function.html</a></p> <p>The <code>f@x</code> syntax is simply shorthand for <code>f[x]</code>.</p> <p>Finally, <code>f@@list</code> is shorthand for <code>Apply[f, list]</code>:</p> <p><a href="http://reference.wolfram.com/mathematica/ref/Apply.html" rel="nofollow noreferrer">http://reference.wolfram.com/mathematica/ref/Apply.html</a></p> <p>So taildiffs as defined above is just a terse (perhaps cryptic) version of this:</p> <pre><code>Apply[Transpose[Function[{x,y}, {x, Prepend[Differences[y],0]}], Transpose[data]] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload