gpt4 book ai didi

r - 格式化来自 R 表的 html 输出,如带有选项 "Do not repeat item labels"的 excel 数据透视表

转载 作者:行者123 更新时间:2023-12-04 21:42:24 25 4
gpt4 key购买 nike

我已经类型转换 (reshape2) 具有以下结构的数据帧表:

地区 |学校

|Region | school | Year1 | Year2  |
-----------------------------------
|R1 | S1 | Value1| Value2 |
|R1 | S2 | Value3| Value4 |
|R1 | S3 | Value5| Value6 |
|R2 | S4 | Value7| Value8 |
|R2 | S5 | Value9| Value10|

因此,对于每个地区,都有严格的学校。我只想显示该区域一次,如下所示:
|Region | school | Year1 | Year2  |
-----------------------------------
|R1 | S1 | Value1| Value2 |
| | S2 | Value3| Value4 |
| | S3 | Value5| Value6 |
|R2 | S4 | Value7| Value8 |
| | S5 | Value9| Value10|

我很确定我在许多 xtables 中看到过这个 - 但我现在找不到和例子。有任何想法吗?如果您对我正在尝试做的事情有疑问;在 Excel 中,可以在数据透视表工具 -> 设计 -> 报告布局下找到此选项(我认为这是默认设置)。

在我的类型转换数据帧(dput)下方:
structure(list(region = c("Hovedstaden", "Hovedstaden", "Hovedstaden", 
"Hovedstaden", "Hovedstaden", "Midtjylland", "Midtjylland", "Midtjylland",
"Midtjylland", "Midtjylland", "Midtjylland", "Midtjylland", "Midtjylland",
"Midtjylland", "Midtjylland", "Midtjylland", "Midtjylland", "Midtjylland",
"Midtjylland", "Midtjylland", "Nordjylland", "Nordjylland", "Nordjylland",
"Nordjylland", "Nordjylland", "Sjælland", "Sjælland", "Sjælland",
"Sjælland", "Sjælland", "Sjælland", "Sjælland", "Syddanmark",
"Syddanmark", "Syddanmark", "Syddanmark", "Syddanmark", "Syddanmark",
"Syddanmark"), school = c("Campus Bornholm", "CPH - Uddannelsescenter København Vest",
"Erhvervsskolen Nordsjælland", "Københavns Tekniske Skole",
"TEC Teknisk Erhvervsskole Center", "Den jydske Haandværkerskole",
"Herningsholm Erhvervsskole", "Holstebro Tekniske Skole", "Learnmark Horsens",
"Professionshøjskolen VIA University College", "Skive Tekniske Skole",
"Teknisk Skole Silkeborg", "Tradium", "Tradium, Tekniske erhvervsudd. og Teknisk Gymnasium, HTX",
"Uddannelsescenter Holstebro", "UddannelsesCenter Ringkøbing-Skjern",
"UddannelsesCenter Ringkøbing-Skjern, teknisk skole", "Viden Djurs",
"Vitus Bering Danmark", "AARHUS TECH", "Erhvervsskolerne Aars",
"EUC Nord", "EUC Nordvest", "Nordvestjysk Uddannelsescenter",
"Tech College Aalborg", "CELF - Center for erhv.rettede udd. Lolland-Falster",
"CEUS", "EUC Nordvestsjælland", "EUC Sjælland", "Roskilde Tekniske Skole",
"Roskilde Tekniske Skole - Pulsen", "Selandia - CEU", "EUC Syd",
"EUC Vest", "HANSENBERG", "Odense Tekniske Skole", "Svendborg Erhvervsskole",
"Syddansk Erhvervsskole Odense-Vejle", "Vejle Tekniske Skole"
), `2003` = c(0, 0, 83, 0, 294, 120, 73, 73, 0, 0, 28, 28, 0,
29, 0, 0, 29, 0, 29, 47, 0, 25, 0, 25, 78, 0, 36, 25, 52, 0,
55, 18, 66, 45, 45, 64, 15, 0, 72), `2004` = c(1243, 0, 71, 0,
296, 122, 79, 79, 0, 0, 39, 39, 0, 30, 0, 0, 30, 0, 5, 53, 0,
36, 0, 36, 82, 0, 53, 36, 58, 0, 76, 31, 56, 54, 54, 92, 30,
0, 82), `2005` = c(1397, 0, 80, 0, 348, 132, 123, 123, 0, 0,
44, 0, 0, 37, 0, 0, 37, 0, 37, 61, 0, 65, 65, 0, 143, 0, 56,
40, 61, 0, 57, 26, 76, 53, 53, 119, 34, 0, 102), `2006` = c(1676,
7, 98, 0, 423, 176, 132, 7, 0, 0, 48, 48, 0, 42, 0, 0, 42, 0,
5, 69, 0, 87, 87, 0, 154, 0, 69, 47, 70, 0, 89, 42, 74, 81, 81,
122, 38, 0, 119), `2007` = c(6, 6, 94, 94, 416, 190, 118, 13,
0, 13, 57, 0, 0, 62, 0, 62, 0, 62, 0, 71, 7, 72, 72, 0, 193,
0, 69, 53, 71, 78, 0, 42, 82, 68, 68, 108, 52, 0, 142), `2008` = c(2090,
2090, 79, 79, 345, 158, 113, 9, 0, 6, 42, 0, 0, 31, 0, 0, 0,
31, 0, 62, 423, 76, 76, 0, 141, 53, 0, 31, 43, 90, 0, 26, 84,
62, 62, 0, 28, 193, 0), `2009` = c(1687, 1687, 58, 0, 237, 90,
55, 0, 0, 55, 23, 23, 28, 0, 28, 0, 0, 28, 0, 42, 244, 37, 37,
0, 68, 38, 0, 44, 34, 59, 0, 21, 41, 39, 39, 0, 15, 104, 0),
`2010` = c(1043, 1043, 70, 70, 285, 113, 56, 0, 56, 0, 32,
0, 29, 0, 29, 0, 0, 29, 0, 52, 287, 52, 52, 0, 75, 41, 0,
23, 34, 56, 0, 27, 52, 35, 0, 0, 35, 145, 0), `2011` = c(1223,
0, 66, 0, 279, 130, 73, 0, 73, 0, 22, 0, 23, 0, 23, 0, 0,
0, 0, 53, 0, 44, 44, 0, 90, 51, 0, 35, 32, 65, 0, 28, 35,
45, 0, 0, 31, 141, 0), `2012` = c(0, 0, 72, 0, 349, 130,
93, 0, 93, 0, 46, 0, 26, 0, 9, 0, 0, 0, 0, 56, 0, 56, 0,
0, 101, 41, 0, 38, 28, 76, 0, 34, 44, 47, 0, 0, 32, 186,
0), `2013` = c(0, 0, 56, 0, 286, 142, 79, 0, 79, 0, 25, 0,
27, 0, 27, 0, 0, 0, 0, 65, 0, 56, 0, 0, 112, 41, 0, 19, 39,
72, 0, 36, 44, 49, 0, 0, 19, 143, 0), `2014` = c(0, 0, 18,
0, 49, 38, 26, 0, 26, 0, 7, 0, 7, 0, 7, 0, 0, 0, 0, 7, 0,
8, 0, 0, 20, 9, 0, 18, 10, 9, 0, 10, 11, 15, 0, 0, 7, 36,
0)), .Names = c("region", "school", "2003", "2004", "2005",
"2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013",
"2014"), row.names = c(NA, -39L), class = "data.frame")

最佳答案

函数 htmlTable ind Gmisc 包可以提供两级 coloumnlabels 和 rowlabels(使用 cgroup/rgroup 和 n.croup/n.rgroup。参见例如 http://timelyportfolio.blogspot.dk/2013/04/tables-are-like-cockroaches.htmlhttp://gforge.se/2013/02/tables-from-r-into-word/

关于r - 格式化来自 R 表的 html 输出,如带有选项 "Do not repeat item labels"的 excel 数据透视表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23147891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com