Skip to content

there doesn't seem to be an elegant way to combine groupBy and pivoting . am I missing something? #76

Answered by pbeshai
disleyland asked this question in Q&A
Discussion options

You must be logged in to vote

You can pass as many tidy functions to the second argument of groupBy as you'd like:

const data = [
  { group: 'a', type: 'one',   place: 'canada',   val: 1 },
  { group: 'a', type: 'one',   place: 'usa',      val: 10 },
  { group: 'b', type: 'one',   place: 'campbell', val: 4 },
  { group: 'b', type: 'one',   place: 'brampton', val: 8 },
  { group: 'a', type: 'two',   place: 'brampton', val: 7 },
  { group: 'b', type: 'two',   place: 'boston',   val: 3 },
  { group: 'b', type: 'two',   place: 'usa',      val: 11 },
  { group: 'a', type: 'three', place: 'canada',   val: 20 },
];

output = tidy(
  data,
  groupBy(['group'], [
    pivotWider({
      namesFrom: 'place',
      valuesFrom: 'val',

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@disleyland
Comment options

Answer selected by pbeshai
Comment options

You must be logged in to vote
1 reply
@disleyland
Comment options

Comment options

You must be logged in to vote
1 reply
@disleyland
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants