Ramda.js R.transpose() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.transpose(rows) takes a list of lists (a 2D list) and swaps its rows and columns: item j of every row becomes part of new row j (official Ramda docs). n rows of length x become x rows of length n, and the input is never changed.

Added in v0.19.0: R.transpose is stable — not deprecated, experimental, or non-standard. Warning: short rows are skipped, not padded, so with uneven rows items slide into earlier columns.

Syntax

Call R.transpose. Start with this line.

Ramda
R.transpose(rows) (one argument) Type [[a]] → [[a]]
CallWhat it does
R.transpose(rows) (one argument) Type [[a]] → [[a]]Primary signature.
R.transpose(...)Call the list helper.

Prefer import { transpose } from "ramda" when you want a named import.

Library declarations
Ramda
R.transpose(rows) (one argument) Type [[a]] → [[a]]

Parameters

ParameterDescription
rowsRequired. An array whose items are arrays (or strings); null throws

Return Value

Return ValueDescription
*A new array of new arrays; the original is untouched

Ramda Examples

Example 1 — Official Samples

The three samples from the Ramda docs: tall to wide, wide to tall, and uneven rows.

Ramda
console.log(R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]));    // [[1, 2, 3], ['a', 'b', 'c']]
console.log(R.transpose([[1, 2, 3], ['a', 'b', 'c']]));      // [[1, 'a'], [2, 'b'], [3, 'c']]
console.log(R.transpose([[10, 11], [20], [], [30, 31, 32]])); // [[10, 20, 30], [11, 31], [32]]
Try It Yourself

How It Works

  1. Tall to wide. 3 rows of 2 items become 2 rows of 3: all first items, then all second items.
  2. Wide to tall. 2 rows of 3 become 3 rows of 2 — the reverse of the first call.
  3. Uneven rows. Rows that are too short add nothing to a column, so column 1 is just [11, 31].
  4. New arrays. Every call returns a fresh 2D list; the inputs are not changed.

Example 2 — Column Totals

Each row is one student’s marks; transpose to work subject by subject.

Ramda
//            math science art
const marks = [
  [90, 80, 70],   // Ada
  [60, 75, 85],   // Bob
  [70, 95, 60]    // Cy
];

const subjects = R.transpose(marks);
console.log(subjects);                             // [[90, 60, 70], [80, 75, 95], [70, 85, 60]]
console.log(R.map(R.sum, subjects));               // [220, 250, 215]
console.log(R.map(R.apply(Math.max), subjects));   // [90, 95, 85]
Try It Yourself

How It Works

  1. Rows. marks has one row per student and one column per subject.
  2. Transpose. Now each row is one subject: math is [90, 60, 70].
  3. Totals. R.map with R.sum adds up each subject: [220, 250, 215].
  4. Top mark. R.apply(Math.max) spreads each subject list into Math.max: [90, 95, 85].

Example 3 — Unzip a List of Pairs

Split [name, mark] pairs into two lists, then zip them back together.

Ramda
const pairs = [['Ada', 90], ['Bob', 75], ['Cy', 82]];

const [names, scores] = R.transpose(pairs);
console.log(names);                 // ['Ada', 'Bob', 'Cy']
console.log(scores);                // [90, 75, 82]
console.log(R.zip(names, scores));  // [['Ada', 90], ['Bob', 75], ['Cy', 82]]
Try It Yourself

How It Works

  1. Pairs. Each inner array is one row of two columns: name and mark.
  2. Transpose. The result has two rows: all names, then all marks.
  3. Destructure. const [names, scores] takes those two rows as separate lists.
  4. Round trip. R.zip pairs them up again, so transpose acts as Ramda’s “unzip”.

Example 4 — Uneven Rows Shift Items

See how short rows move items, and pad the rows to keep every item in its column.

Ramda
const ragged = [[10, 11], [20], [], [30, 31, 32]];

const flipped = R.transpose(ragged);
console.log(flipped);                  // [[10, 20, 30], [11, 31], [32]]
console.log(R.transpose(flipped));     // [[10, 11, 32], [20, 31], [30]]

const width = Math.max(...R.map(R.length, ragged));               // 3
const pad = row => R.concat(row, R.repeat(null, width - row.length));
console.log(R.transpose(R.map(pad, ragged)));
// [[10, 20, null, 30], [11, null, null, 31], [null, null, null, 32]]
Try It Yourself

How It Works

  1. Skipped. Row [20] has no item 1, so 31 lands right after 11 — the gap disappears.
  2. No round trip. Transposing again gives [[10, 11, 32], …], not the original rows.
  3. Pad. R.length finds the widest row (3), and R.concat + R.repeat(null, …) fill each row to that width.
  4. Stable columns. With equal rows, every value keeps its place and null marks what was missing.

Example 5 — Rotate a Grid 90°

Combine transpose with R.reverse to turn a grid right or left.

Ramda
const grid = [
  [1, 2, 3],
  [4, 5, 6]
];

const rotateRight = R.pipe(R.transpose, R.map(R.reverse));
const rotateLeft = R.pipe(R.transpose, R.reverse);

console.log(R.transpose(grid));   // [[1, 4], [2, 5], [3, 6]]
console.log(rotateRight(grid));   // [[4, 1], [5, 2], [6, 3]]
console.log(rotateLeft(grid));    // [[3, 6], [2, 5], [1, 4]]
Try It Yourself

How It Works

  1. Transpose. Columns become rows: [1, 4], [2, 5], [3, 6].
  2. Right. R.reverse on each row turns the grid clockwise: the bottom-left 4 moves to the top-left.
  3. Left. Reversing the order of the rows instead turns it counter-clockwise: [3, 6] comes first.
  4. Reusable. R.pipe saves each rotation as a function you can call on any grid.

Browser & Runtime Support

R.transpose() has been in Ramda since v0.19.0. It is two plain loops over arrays, so it works wherever Ramda loads.

✓ Ramda 0.19.0+ · Any JS runtime

Ramda.js R.transpose()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda 0.19+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.transpose() Universal

Bottom line: Safe in any project on Ramda 0.19 or newer; results are identical in 0.30 and 0.32. The array destructuring and spread used in some examples need an ES2015+ engine (all modern browsers and Node). These labs load [email protected].

Frequently Asked Questions

R.transpose(rows) turns the rows of a list of lists into columns. Item j of every row goes into new row j, so R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]) returns [[1, 2, 3], ['a', 'b', 'c']].
Missing items are skipped, not filled with undefined. The official sample R.transpose([[10, 11], [20], [], [30, 31, 32]]) returns [[10, 20, 30], [11, 31], [32]], so 31 ends up next to 11. Pad short rows first if positions matter.
Not quite. R.zip takes exactly two lists and stops at the shorter one: R.zip([1, 2, 3], ['a']) is [[1, 'a']]. R.transpose takes any number of rows and keeps the extra items: R.transpose([[1, 2, 3], ['a']]) is [[1, 'a'], [2], [3]].
Ramda has no unzip function; R.transpose does the job. R.transpose([['Ada', 90], ['Bob', 75]]) returns [['Ada', 'Bob'], [90, 75]], which you can destructure into two lists.
No. It builds a new outer array and new inner arrays. The items themselves are not copied, so objects inside the grid are shared with the original.
No. R.transpose has been part of Ramda since v0.19.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.traverse()

Map a list and sequence the results in one step.

R.traverse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful