observablehq

How to do pandas-like shift operation on an arquero table (or other tables) for plotting in ObservableHQ?


For example, you might have something like this in your plotting spec for a scatter:

{"data": {"values": mydata.select("x", "y")}, ... }

But suppose you want to plot mydata.select("x").slice(5) vs mydata.select("y").slice(-5) ... is there a fast or inline way of doing this?


Solution

  • There are many ways of slicing an array in JavaScript, the easiest probably being Array.slice(); it returns a new array with the copied data.

    For performance, if the array is a typed array and you just want to read from it, you'll want to use Array.subarray() instead.

    Arquero itself has a slice verb, which returns a sliced view (again, without copying the data).

    If your data is a generic iterable, you can also convert it to an array then slice that array: Array.from(data).slice(…)