creating an tibble with a single variable which is also a tibble

For purposes of working on a different problem, I tried to create a simple tibble with one variable, which I wanted to be a list column, in which there was a single tibble. I thought that this code would do that:

x.tbl <- tibble(a = tibble(var.1 = c(1, 2, 3), 
                                     var.2 = c("A", "B", "C"))) 
#> [1] 3

Created on 2020-03-21 by the reprex package (v0.3.0)

I expected nrow(x.tbl) to be 1. I thought x.tbl was a tibble with a single variable, a, and for which there was only a single observation. Clearly, it is not. How could I create such a structure? And, just for my education, why doesn't this code do what I want?

Is this what you are looking for?

x.tbl <- tibble(a = list(tibble(var.1 = c(1, 2, 3), 
                           var.2 = c("A", "B", "C"))))


It is! Thanks! Should have thought of this myself . . .

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.