Hi @Gabbi,
You need an ID column that uniquely identifies which values of age, name, and height correspond to a single row in the desired output. With that, you can achieve this transformation with the following code:
library(tidyverse)
data <-
tribble(
~variable, ~value,
"age", "23",
"age", "44",
"age", "21",
"name", "a",
"name", "b",
"name", "c",
"height", "1",
"height", "2",
"height", "3"
)
data %>%
mutate(id = rep(1:3, 3)) %>%
pivot_wider(
id_cols = id,
names_from = variable,
values_from = value
)
#> # A tibble: 3 x 4
#> id age name height
#> <int> <chr> <chr> <chr>
#> 1 1 23 a 1
#> 2 2 44 b 2
#> 3 3 21 c 3