如何解决在R中使用adorn_totals函数时的错误



使用janitor::adorn_totals("row"):时,我收到以下错误消息

"adorn_totals(.,"行"(中出错:尝试重新添加已经添加的合计维度";

这是我的数据集的标题:

structure(list(code_1 = c("M01", "C03", "M99", "C05", "O01", 
"C07"), regroupement_elsan = c("Gastro", "Ophtalmo", "Divers médecine", 
"Gynéco", "Accouchements", "bouche et dents"), actes_2019 = c(9179, 
5589, 6024, 4150, 4028, 3458), actes_2020 = c(7933, 4167, 3740, 
2994, 3348, 2206), actes_2021 = c(6504, 5505, 4682, 3376, 3226, 
3035), sejours_2019 = c(1631, 2502, 1028, 852, 1455, 1288), sejours_2020 = c(1335, 
1819, 726, 574, 1371, 801), sejours_2021 = c(1109, 2416, 825, 
657, 1259, 1106), tx_0_nuit_2019 = c("3.92397302268547", "90.7673860911271", 
"32.9766536964981", "57.5117370892019", "0.206185567010309", 
"98.9130434782609"), tx_0_nuit_2020 = c("3.29588014981273", "92.9081913139087", 
"47.1074380165289", "59.581881533101", "0.291757840991977", "99.250936329588"
), tx_0_nuit_2021 = c("3.6068530207394", "95.4470198675497", 
"18.3030303030303", "60.2739726027397", "0.158856235107228", 
"98.7341772151899"), pourcentage = c(5.37796226165473, 4.55191916519208, 
3.87140518282095, 2.79151300666457, 2.66748251170021, 2.50955034811226
), pourcentage_cumule = c(78.4062908267046, 82.9582099918967, 
86.8296151747176, 89.6211281813822, 92.2886106930824, 94.7981610411947
)), row.names = c(NA, -6L), class = c("tabyl", "tbl_df", "tbl", 
"data.frame"), core = structure(list(code_1 = c("M01b", "C01", 
"C02", "C04", "M01", "C03", "M99", "C05", "O01", "C07", "C08", 
"C99", "C98", "C10", "C06", "M03", "O02", "M02", "M04", "C01b", 
"O03", "S99", "***", "C10b", "M05", "M98", "O04"), regroupement_elsan = c("Endoscopies 
digestives", 
"Ortho (+ rhumato et rachis)", "Chirurgie digestive", "Uro-néphro", 
"Gastro", "Ophtalmo", "Divers médecine", "Gynéco", "Accouchements", 
"bouche et dents", "Tissus mou et chir plastique", "Divers chir", 
"Chir esth et hors sécu", "Chir thoracique et vasculaire", "ORL Stomato sf bouche et 
dent", 
"Pneumologie", "Obstétrique autre (hors IVG)", "Cardio Vasc (médecine)", 
"Neurologie", "Rachis", "IVG", "Séances autres", "Autres", "Chir thoracique", 
"Soins palliatifs", "Vasculaire interventionnel", "Néo nat"), 
actes_2019 = c(36079, 29520, 14618, 6515, 9179, 5589, 6024, 
4150, 4028, 3458, 2137, 2180, 575, 449, 866, 388, 294, 311, 
714, 395, 292, 1842, 10, 0, 4, 0, 1), actes_2020 = c(30192, 
25451, 12845, 7376, 7933, 4167, 3740, 2994, 3348, 2206, 2107, 
1477, 575, 437, 337, 897, 193, 218, 267, 308, 118, 737, 8, 
4, 0, 11, 5), actes_2021 = c(42333, 24055, 13735, 8196, 6504, 
5505, 4682, 3376, 3226, 3035, 2571, 1134, 689, 511, 352, 
272, 181, 161, 138, 106, 82, 61, 18, 8, 7, 0, 0), sejours_2019 = c(6992, 
5493, 2577, 1221, 1631, 2502, 1028, 852, 1455, 1288, 540, 
397, 236, 158, 260, 63, 148, 101, 90, 44, 246, 1820, 4, 0, 
1, 0, 1), sejours_2020 = c(5811, 4946, 2220, 1220, 1335, 
1819, 726, 574, 1371, 801, 554, 269, 221, 140, 94, 42, 109, 
79, 58, 34, 98, 720, 2, 1, 0, 1, 5), sejours_2021 = c(7922, 
5144, 2523, 1451, 1109, 2416, 825, 657, 1259, 1106, 649, 
264, 278, 162, 111, 51, 108, 69, 30, 21, 77, 54, 7, 1, 2, 
0, 0), tx_0_nuit_2019 = c("96.0955377574371", "63.5718186783179", 
"41.4435389988359", "36.2817362817363", "3.92397302268547", 
"90.7673860911271", "32.9766536964981", "57.5117370892019", 
"0.206185567010309", "98.9130434782609", "72.5925925925926", 
"53.904282115869", "13.9830508474576", "96.2025316455696", 
"50.7692307692308", "42.8571428571429", "85.1351351351351", 
"72.2772277227723", "11.1111111111111", "4.54545454545455", 
"100,0", "100,0", "100,0", "0,0", "0,0", "0,0", "0,0"), tx_0_nuit_2020 = 
c("96.0936155567028", 
"67.3069146785281", "40.5855855855856", "34.344262295082", 
"3.29588014981273", "92.9081913139087", "47.1074380165289", 
"59.581881533101", "0.291757840991977", "99.250936329588", 
"76.3537906137184", "49.814126394052", "11.7647058823529", 
"99.2857142857143", "53.1914893617021", "16.6666666666667", 
"74.3119266055046", "81.0126582278481", "25.8620689655172", 
"8.82352941176471", "98.9795918367347", "100,0", "100,0", 
"100,0", "0,0", "0,0", "20,0"), tx_0_nuit_2021 = c("96.7053774299419", 
"73.2892690513219", "51.0503369005153", "41.9021364576154", 
"3.6068530207394", "95.4470198675497", "18.3030303030303", 
"60.2739726027397", "0.158856235107228", "98.7341772151899", 
"83.9753466872111", "60.2272727272727", "50,0", "94.4444444444444", 
"72.972972972973", "1.96078431372549", "81.4814814814815", 
"85.5072463768116", "43.3333333333333", "52.3809523809524", 
"100,0", "100,0", "100,0", "100,0", "0,0", "0,0", "0,0")), row.names = c(NA, 
-27L), class = "data.frame"), tabyl_type = "two_way", totals = "row")

我试过的代码是:

library(janitor)
autres %>%
adorn_totals("row")

有人能帮忙吗?我确实在用于生成数据帧的数据帧上使用了adorn_totals函数;autres";,但我确保了;合计";不在数据帧中";autres";不再

使用您共享为x:的对象

x %>%
untabyl() %>%
adorn_totals()

为什么有效:

您可以在共享对象tabyl_type = "two_way", totals = "row"的末尾看到。这些属性与您正在使用的data.frame一起存储。当你第二次尝试adorn_totals()时,看门人会检查这一点并出错。

当您调用untabyl()时,它会剥离这些属性。则adorn_totals()成功。

我注意到你有一个累计百分比栏。如果需要,您可以精确控制哪些列在adorn_totals()中获得合计值-请参阅?adorn_totals...参数了解如何获得合计值,下面是一个示例:https://stackoverflow.com/a/69759313.

最新更新