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

    Function pivotLonger

    • Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to tidyr::pivot_longer() in R. The result has the columns not selected, a column per part of the selected names (namesTo), and the value column (valuesTo), or with ".value" in namesTo one value column per value of that part. The values of the selected columns are combined into one type: numbers with booleans give numbers; strings with either are an error.

      Parameters

      Returns DataFrame

      const wide = { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, 7.2] };
      pivotLonger(wide, { cols: ["t1", "t2"], namesTo: "time", valuesTo: "score" });
      // { id: ["s1", "s1", "s2", "s2"], time: ["t1", "t2", "t1", "t2"], score: [5.1, 6.3, 4.8, 7.2] }