I'm having trouble using the pivot_longer on blocks of variables. Suppose I have this:
and I want this:
dfwide <- structure(list(date = structure(c(1577836800, 1577923200, 1578009600,
1578096000, 1578182400, 1578268800), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), x1_a = c(20, 15, 12, NA, 25, 27), x1_b = c(33,
44, 85, 10, 12, 3), x1_c = c(70, 20, 87, 11, 20, 5), x2_a = c(85,
65, 33, 46, 82, 9), x2_b = c(87, 25, 55, 64, 98, 5), x2_c = c(77,
51, 92, 20, 37, 98)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
##Tried:
dfwide %>%
pivot_longer(cols = -date,
names_sep = c("x1", "x2"),
names_to = c("a", "b", "c"),
values_to = "value")

