Coder Social home page Coder Social logo

Comments (3)

jheer avatar jheer commented on May 4, 2024

If keys are provided both the source key and target withKey must be properly defined. By default the data object is used as the key for the source data. This default is helpful if your input data is simple strings or numbers rather than objects.

If no withKey is provided, then zip simply combines elements based on their position in their respective arrays. Source item 0 is zipped with target item 0, and so on, in a one-to-one fashion.

In the use case above, do you want to map a single global stats object with every element in the barley data? If so, I believe the following modification to zip should do the trick:

var zlen = zdata.length;
for (i=0, len=data.length; i<len; ++i) {
  d = data[i];
  d[as] = map ? map[key(d)] : zdata[i % zlen];
}

In the case that the target data is shorter than the source data, the target data indices simply cycle. For stats data with only one entry, zlen is 1 and so the modulo operation (i % zlen) will always return 0. For better or worse, these semantics are more similar to how R handles arrays... Does the above address your need?

from vega.

jheer avatar jheer commented on May 4, 2024

As of commit 2d5f025, "zipping" two data sets by index now cycles the indices if the secondary data set is shorter than the primary data set.

from vega.

timelyportfolio avatar timelyportfolio commented on May 4, 2024

Very nice, thanks. Your solution is far more elegant than my proposal (no surprise there).

from vega.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.