npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tidyverse

v0.1.9

Published

`tidyverse` aims at easing data manipulation with javascript. It is inspired by Hadley Wickham's [tidyverse](https://www.tidyverse.org/packages/) `R` package and reproduces its API.

Downloads

34

Readme

tidyverse

tidyverse aims at easing data manipulation with javascript. It is inspired by Hadley Wickham's tidyverse R package and reproduces its API.

So far, one function is implemented:

  • pivot_longer: converts an array of objects from a wider format to a longer format.
    • data: the array to pivot
    • cols: an array of field names
    • name_to: name of the added field

The returned objects will also have an added property value with the value of the pivoted fields.

Wider and Longer data table

Wider data table

In the mock data table below, years are used as column names, when they actually belong to the same dimension "year". The rows contains several values (one for each year).

| name | gender | 2017 | 2018 | 2019 | |-----------|--------|-------|------|-------| | Argentina | female | 34 | 7 | 3 | | Armenia | female | 14.6 | 12 | 19.8 | | Argentina | male | 54 | 32 | 60 | | Armenia | male | 43 | 12 | 25 |

Longer Data table

This longer data table contains the same information, but the years are stored in a unique column. The values are also stored in a newly created column "values". Each row contains a single observation.

| name | gender | year | value | |-----------|--------|------|-------| | Argentina | female | 2017 | 34 | | Armenia | female | 2017 | 14.6 | | Argentina | male | 2017 | 54 | | Armenia | male | 2017 | 43 | | Argentina | female | 2018 | 7 | | Armenia | female | 2018 | 12 | | Argentina | male | 2018 | 32 | | Armenia | male | 2018 | 12 | | Argentina | female | 2019 | 3 | | Armenia | female | 2019 | 19.8 | | Argentina | male | 2019 | 60 |

pivot_longer converts a data table from the wider format to the longer format.

Example

import { pivot_longer } from "tidyverse";

const wider = [
  {
    country: "Argentina",
    gender: "female",
    2015: 0.3,
    2016: 0.7,
    2017: 0.7
  },
  {
    country: "Armenia",
    gender: "female",
    2015: 7.2,
    2016: 7.7,
    2017: 7.6
  }
];

const longer = pivot_longer({
  data: wider,
  cols: [2015, 2016, 2017],
  name_to: "year"
})

console.log(longer);
// [
//   {
//     "country": "Argentina",
//     "gender": "female",
//     "year": 2015,
//     "value": 0.3
//   },
//   {
//     "country": "Armenia",
//     "gender": "female",
//     "year": 2015,
//     "value": 7.2
//   },
//   {
//     "country": "Argentina",
//     "gender": "female",
//     "year": 2016,
//     "value": 0.7
//   },
//   {
//     "country": "Armenia",
//     "gender": "female",
//     "year": 2016,
//     "value": 7.7
//   },
//   {
//     "country": "Argentina",
//     "gender": "female",
//     "year": 2017,
//     "value": 0.7
//   },
//   {
//     "country": "Armenia",
//     "gender": "female",
//     "year": 2017,
//     "value": 7.6
//   }
//  ]