melt-data

0.2.1 • Public • Published

Build Status

Melt.js

Javascript library inspired by the R reshape package by Hadley Wickham.

Melt provides two functions melt and cast. How do they work?

First, they presume you have your data in the form of a list of objects. That looks like this:

var data = [
  {key1: 1, key2: 2},
  {key1: 2, key2: 3},
  {key1: 3, key2: 5},
];

But if you need the keys to be represented as a value, then melt can come to the rescue. Let's take a look at some examples:

Examples

Melt: jsfiddle

Cast: jsfiddle

API

melt(data, keep, varName, valName, noAddId)

  • data list of objects - data to melt
  • keep array of strings - names of object keys to keep
  • varName string - name of the key to use in the molten objects for the former keys (those not in keep)
  • varName string - name of the key to use in the molten objects for the former values

cast(data, keep, fun, funArgs ...)

  • data list of objects - data to cast
  • keep array of strings - names of object keys to keep (the "GROUP BY" keys)
  • fun function - a function used to aggregate values accross grouped objects
  • funArgs mixed - arguments to passed to fun

cast.sum(name, cols) - convience function to summarize data with cast

  • name string name of resulting object key with sum results
  • cols string or array - names of keys to totaled in the sum. Key values should respond to +.

cast.sum(name) - convience function to sum data with cast

  • name string - special case of cast.sum(name, cols) name is treated as both name and cols.

cast.count(name) - convience function to count data with cast

  • name string - name of resulting object key with which to count objects with common keep values

License

Apache 2

Readme

Keywords

none

Package Sidebar

Install

npm i melt-data

Weekly Downloads

1

Version

0.2.1

License

Apache-2.0

Last publish

Collaborators

  • jrideout