'Pivot_longer/pivot_wider on more than one column
I've the following dataset
The code is as follows:
df = structure(list(UID = structure(1:5, .Label = c("C001", "C002",
"C003", "C004", "C005"), class = "factor"), Shop_Code = structure(1:5, .Label = c("A",
"B", "C", "D", "E"), class = "factor"), Shop_District_Code = structure(1:5, .Label = c("AA",
"BB", "CC", "DD", "EE"), class = "factor"), Bread = c(5, 4.8,
4.5, 4.2, 5), Apple = c(3, 2.8, 3.1, 3.4, 3.2), Coke = c(3, 2.6,
2.8, 3, 3.1), Bread_1 = c(NA, NA, NA, 4.6, NA), Apple_1 = c(NA,
NA, NA, 2.6, NA), Coke_1 = c(NA, NA, NA, 2.2, NA), Bread_2 = c(NA,
NA, 4.6, NA, 5.1), Apple_2 = c(NA, NA, 3, NA, 3.3), Coke_2 = c(NA,
NA, 3, NA, 3.2), Bread_3 = c(NA, NA, 4.8, NA, NA), Apple_3 = c(NA,
NA, 2.7, NA, NA), Coke_3 = c(NA, NA, 2.6, NA, NA)), class = "data.frame", row.names = c(NA,
-5L))
Does anybody know how I can append the extended columns to the bottom as rows like the following table using pivot_wider/pivot_longer (or any other functions)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


