rStats.js v1.3.0
    Preparing search index...

    Function pivotWider

    • Reshapes a data frame from long to wide: the values of namesFrom become columns, filled from valuesFrom. Equivalent to tidyr::pivot_wider() in R. One row per combination of the id columns (in order of first appearance), the new columns in order of first appearance of their names (unless namesSort). A cell that no row fills is valuesFill (default missing). A cell that several rows fill is an error unless valuesFn summarises the values (tidyr makes a list column there, which a data frame here cannot hold).

      Parameters

      Returns DataFrame

      const long = { id: ["s1", "s1", "s2"], time: ["t1", "t2", "t1"], score: [5.1, 6.3, 4.8] };
      pivotWider(long, { namesFrom: "time", valuesFrom: "score" });
      // { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, null] }