多列上的 Pivot_longer/pivot_wider
我有以下数据集
代码如下:
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))
有人知道如何使用pivot_wider/pivot_longer(或任何其他函数)将扩展列作为如下表的行附加到底部吗?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)