How to perform the "uncollapsing" of a one row data frame or array to multiple rows in R
12:58 18 Apr 2026

I suppose this is kind of a strange question, but I want to "uncollapse" a row of data in R, as follows. The original data is, for example, a data frame row where v1 = 1, v2 = 2, as here:

collapsed = structure(list(v1 = 1L, v2 = 2L, v3 = 3L, v4 = 4L, v5 = 5L), class = "data.frame", row.names = c(NA, 
-1L))

I want the end result to look like this:

uncollapsed = structure(list(v1 = c(1L, 1L, 1L, 1L, 1L), v2 = c(NA, 2L, 2L, 
2L, 2L), v3 = c(NA, NA, 3L, 3L, 3L), v4 = c(NA, NA, NA, 4L, 4L
), v5 = c(NA, NA, NA, NA, 5L)), class = "data.frame", row.names = c(NA, 
-5L))

There are packages like collapse and tidyr that provide functions for collapsing data, but I can't find functions that do the opposite. I am running a loop right now to create the "uncollapsed" data frame. I'm wondering if there are better ways to do this, since my real workflow involves billions of rows of data.

r combinations tidyr r-collapse