Ply.js
ply.js is a small javascript library designed to to group, summarize, and manipulate tabular data sets, using an API inspired by Hadley Wickham's dplyr library for R.
Install / Use
/learn @hamilton/Ply.jsREADME
ply.js
ply.js is a small javascript library designed to to group, summarize, and manipulate tabular data sets, using an API inspired by Hadley Wickham's dplyr library for R. It's meant to work in browsers with the kind of tabular data you might encounter on the web - arrays of objects.
Here's an example:
let data = [
{u: true, v: true, w: 'h', x: 'a', y: 1, z: 100},
{u: false, v: true, w: 'h', x: 'a', y: 1, z: 100},
{u: true, v: true, w: 'i', x: 'a', y: 1, z: 100},
{u: false, v: true, w: 'i', x: 'a', y: 1, z: 100},
...
]
let sd = new Ply(data)
.group('w', 'x') // groups the data by variables w and x
.reduce({ // describes what new variables to create with our grouping
ySum: (arr) => arr.reduce((acc,v)=>acc+v.y,0),
yLength: (arr) => arr.length
})
.transform() // returns the results
group a small data set and sum / count the values.
let data = [
{date: '2010-01-02', color: 'green', x: 100},
{date: '2010-01-02', color: 'green', x: 120},
{date: '2010-01-03', color: 'green', x: 142},
{date: '2010-01-03', color: 'green', x: 130},
{date: '2010-01-02', color: 'red', x: 70},
{date: '2010-01-02', color: 'red', x: 87},
{date: '2010-01-03', color: 'red', x: 95},
{date: '2010-01-03', color: 'red', x: 99}
]
// 1. group by color and date
// 2. get length of groups, as well as sum of x per grouping
let byColorAndDate = new Ply(data)
.group('date', 'color')
.reduce({
xSum: arr => arr.reduce((acc,v)=>acc+v.x, 0),
xLength: arr => arr.length
})
.transform()
get mean, median, and standard deviation of groups
Here, we use some reducer helper functions to get summary statistics of our group.
let data = [
{date: '2018-01-02', color: 'green', x: 100},
{date: '2018-01-02', color: 'green', x: 120},
{date: '2018-01-03', color: 'green', x: 142},
{date: '2018-01-03', color: 'green', x: 130},
{date: '2018-01-02', color: 'red', x: 70},
{date: '2018-01-02', color: 'red', x: 87},
{date: '2018-01-03', color: 'red', x: 95},
{date: '2018-01-03', color: 'red', x: 99},
... // let's say 1,000 more rows
]
let summary = new Ply(data)
.group('date', 'color')
.reduce({
mean: Ply.mean('x'),
median: Ply.median('x'),
stdev: Ply.standardDeviation('x'),
IQR: Ply.IQR('x'),
q75: Ply.quantile(.75, 'x')
})
.transform()
API
basic features
new Ply(data)Creates a new Ply object with data..group(...facets)Creates a new grouped data set based on the facet keys. The resulting object has keys based on the facet combinations, and values which are the row elements that contain those facets..reduce({...newVariableFunctions})- reduces a group data set and outputs new variables based on the argument passed..map(mapFunction)- functions just like the arraymapfunction, but works on both grouped and ungrouped Plys..select(fieldsOrSelectFunction)- selects columns from a Ply object.
reducer helper functions
All the reducer helper functions return a function that takes an array, pulls out all the data associated with key, then returns the output of that function.
Here's how they look in practice:
let data = [
{facet: 'a', x: 10},
{facet: 'b', x: 15},
...
]
const ply = new Ply(data)
let out = ply
.group('facet')
.reduce({
avg: Ply.mean('x'),
sd: Ply.standardDeviation('x')
})
.transform()
Alternatively, you can just use them directly.
let mean = Ply.mean('x')(data)
functions
Ply.sum(key)returns a sum.Ply.mean(key)returns the mean.Ply.variance(key)returns the variance, calculated via Welford's method.Ply.standardDeviation(key)returns the standard deviation.Ply.covariance(key1, key2)returns the covariance.Ply.correlation(key1, key2)returns the correlation.Ply.spearman(key1, key2)returns the spearman correlation coefficient.Ply.quantile(q, key)returns the value at quantileq.Ply.median(key)shorthand forPly.quantile(.5, key).Ply.IQR(key)returns the inter-quartile range.Ply.mode(key)returns the mode.
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
ui-ux-pro-max-skill
60.4kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
ui-ux-pro-max-skill
60.4kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
