Dplyr:如何在数据透视表中按分类组重新排列和拆分数据框 Table 在 R 中显示摘要统计信息

Dplyr: How to Rearrange and Split a Dataframe by A Categorical Group Within a Pivot Table Showing Summary Statistics in R

问题:

如果这是重复,我深表歉意,因为我不知道什么是我想要实现的目标的正确术语。我有一个名为 Country 的分类变量,我想直观地显示七个声学参数 (请参阅下面的数据结构和已经生成的摘要 table)

根据数据,我使用 dplyr package (见下文)生成了描述性统计 (mean, standard deviation, standard error, min, max, q25, q75, and the coefficient of variation - CV) 的摘要 table。

我想生成 split version 我已经创建的 (见下文) 按分类值 [=15] 分组=],因此,descriptive statistics 彼此堆叠成一个 table (arranged similarly to the example supplied).

正如在下面的示例中所观察到的,有一个名为 Year 的列,它漂亮而整齐地显示了出版物中每年的汇总统计数据。我的目标是制作一个类似麋鹿的例子,虽然,the 'Year' column would be called Country,而不是年,会有 two countries 的相似位置(如示例中的 Year - 见下文)并标记为“荷兰和法国”(如在虚拟数据中)。

正如在下面的示例中所观察到的,有一个名为 Year 的列,它漂亮而整齐地显示了出版物中每年的汇总统计数据。我的目标是制作一个类似麋鹿的例子,尽管 the 'Year' column (as shown in the example) would be called Country. I basically want to replicatethedescriptive summary statistics tablethat I havealready produced**(see below)** in the same arrangement (columns and rows) with an extra single column named 'Country' (located before the column变量) in which two countries (Holland and France) are 堆叠在一个 table` 中,因为结果更易于阅读。

摘要 table 的列名称为:

Country, variable, n (observations), Median, Mean, SD, SE, Min, Max, q25, q75, CV

我一直在研究数据 (下面的虚拟数据) 和汇总统计 R 代码 (下面) 和我无法理解如何做到这一点。

有谁知道如何在 dplyr 中生成这种类型的 table?

如果你能伸出援手,非常感谢?

目的:整理汇总统计table 类似于本例

参考

Morisaka, T., Shinohara, M., Nakahara, F. and Akamatsu, T., 2005. Geographic variations in the whistles among three Indo-Pacific bottlenose dolphin Tursiops aduncus populations in Japan. Fisheries Science, 71(3), pp.568-576

数据结构

'data.frame':   100 obs. of  12 variables:
 $ ID         : int  1 2 3 4 5 6 7 8 9 10 ...
 $ Low.Freq   : int  435 94103292 1 2688 8471 28818 654755585 468628164 342491 2288474 ...
 $ High.Freq  : int  6071 3210 6 7306092 6919054 666399 78 523880161 4700783 4173830 ...
 $ Peak.Freq  : int  87005561 9102 994839015 42745869 32840 62737133 2722 24 67404881 999242982 ...
 $ Delta.Freq : int  5 78 88553 794 5 3859122 782 36 8756801 243169338 ...
 $ Delta.Time : int  1361082 7926 499 5004 3494530 213 64551179 70 797 5 ...
 $ Peak.Time  : int  1465265 452894 545076172 8226275 5040875 700530 1 3639 20141 71712131 ...
 $ Center_Freq: int  61907 8709547 300750537 45862 91417085 79892 47765 5477 18 4186 ...
 $ Start.Freq : int  426355 22073538 680374 41771 54 6762844 599171 108 257451851 438814 ...
 $ End.Freq   : int  71000996 11613579 71377155 1942738 8760748 79 455 374 8 5 ...
 $ Species    : chr  "Truncatus_Tursiops" "Truncatus_Tursiops" "Truncatus_Tursiops" "Truncatus_Tursiops" ...
 $ Country    : chr  "Holland" "Holland" "Holland" "Holland" ...

来自 R-Code

的摘要统计信息 Table
 # A tibble: 9 × 11
      variable    Median       Mean           n          SD          SE   Min       Max   q25       q75    CV
      <chr>        <dbl>      <dbl>       <dbl>       <dbl>       <dbl> <dbl>     <dbl> <dbl>     <dbl> <dbl>
    2 Low.Freq   30645   47718421.   7157763188 160229651.  13082696.       0 936779338 392.   5065917. 336. 
    3 High.Freq   6020.  33588147.   5038222034 126884782.  10360099.       0 825466852  78.5   941394. 378. 
    4 Peak.Freq  45487   74707306.  11206095904 202504621.  16534433.       0 999242982 436.  32466176. 271. 
    5 Delta.Freq 20268.  31612255.   4741838252 113350682.   9255044.       0 754038591  93.2  2282342. 359. 
    6 Delta.Time 16852.  64582719.   9687407814 208416077.  17017101.       0 946706344  70.5  4181862. 323. 
    7 Peak.Time  35342   64781815.   9717272204 190695860.  15570252.       1 964147297 790.   6424504. 294. 
    8 Start.Freq 39416.  54517987.   8177697991 173895386.  14198499.       0 940000382  77.2  2694535  319. 
    9 End.Freq   71317   41475068.   6221260243 132873661.  10849089.       1 856943893 430.   7667247. 320. 

R-代码:

library(dplyr)
library(tidyr)

    #Function to calculate the coefficient of variation
    cv <- function(x) 100*( sd(x)/mean(x))
    
   Summary_Statistics <- Dummy[-1] %>% 
                      dplyr::summarise(across(where(is.numeric), .fns = 
                                 list(n = length(n()),
                                 Median = median,
                                 Mean = mean,
                                 n = sum,
                                 SD = sd,
                                 SE = ~sd(.)/sqrt(n()),
                                 Min = min,
                                 Max = max,
                                 q25 = ~quantile(., 0.25), 
                                 q75 = ~quantile(., 0.75), 
                                 CV = cv
                                 ))) %>% 
  pivot_longer(everything(), names_sep = "_", names_to = c( "variable", ".value"))

虚拟数据

structure(list(ID = 1:100, Low.Freq = c(435L, 94103292L, 1L, 
2688L, 8471L, 28818L, 654755585L, 468628164L, 342491L, 2288474L, 
3915L, 411L, 267864894L, 3312618L, 5383L, 8989443L, 1894L, 534981L, 
9544861L, 3437614L, 475386L, 7550764L, 48744L, 2317845L, 5126197L, 
2445L, 8L, 557450L, 450259742L, 21006647L, 9L, 7234027L, 59L, 
9L, 605L, 9199L, 3022L, 30218156L, 46423L, 38L, 88L, 396396244L, 
28934316L, 7723L, 95688045L, 679354L, 716352L, 76289L, 332826763L, 
6L, 90975L, 83103577L, 9529L, 229093L, 42810L, 5L, 18175302L, 
1443751L, 5831L, 8303661L, 86L, 778L, 23947L, 8L, 9829740L, 2075838L, 
7434328L, 82174987L, 2L, 94037071L, 9638653L, 5L, 3L, 65972L, 
0L, 936779338L, 4885076L, 745L, 8L, 56456L, 125140L, 73043989L, 
516476L, 7L, 4440739L, 612L, 3966L, 8L, 9255L, 84127L, 96218L, 
5690L, 56L, 3561L, 78738L, 1803363L, 809369L, 7131L, 0L, 35502443L
), High.Freq = c(6071L, 3210L, 6L, 7306092L, 6919054L, 666399L, 
78L, 523880161L, 4700783L, 4173830L, 30L, 811L, 341014L, 780L, 
44749L, 91L, 201620707L, 74L, 1L, 65422L, 595L, 89093186L, 946520L, 
6940919L, 655350L, 4L, 6L, 618L, 2006697L, 889L, 1398L, 28769L, 
90519642L, 984L, 0L, 296209525L, 487088392L, 5L, 894L, 529L, 
5L, 99106L, 2L, 926017L, 9078L, 1L, 21L, 88601017L, 575770L, 
48L, 8431L, 194L, 62324996L, 5L, 81L, 40634727L, 806901520L, 
6818173L, 3501L, 91780L, 36106039L, 5834347L, 58388837L, 34L, 
3280L, 6507606L, 19L, 402L, 584L, 76L, 4078684L, 199L, 6881L, 
92251L, 81715L, 40L, 327L, 57764L, 97668898L, 2676483L, 76L, 
4694L, 817120L, 51L, 116712L, 666L, 3L, 42841L, 9724L, 21L, 4L, 
359L, 2604L, 22L, 30490L, 5640L, 34L, 51923625L, 35544L, 59644L
), Peak.Freq = c(87005561L, 9102L, 994839015L, 42745869L, 32840L, 
62737133L, 2722L, 24L, 67404881L, 999242982L, 3048L, 85315406L, 
703037627L, 331264L, 8403609L, 3934064L, 50578953L, 370110665L, 
3414L, 12657L, 40L, 432L, 7707L, 214L, 68588962L, 69467L, 75L, 
500297L, 704L, 1L, 102659072L, 60896923L, 4481230L, 94124925L, 
60164619L, 447L, 580L, 8L, 172L, 9478521L, 20L, 53L, 3072127L, 
2160L, 27301893L, 8L, 4263L, 508L, 712409L, 50677L, 522433683L, 
112844L, 193385L, 458269L, 93578705L, 22093131L, 6L, 9L, 1690461L, 
0L, 4L, 652847L, 44767L, 21408L, 5384L, 304L, 721L, 651147L, 
2426L, 586L, 498289375L, 945L, 6L, 816L, 46207L, 39135L, 6621028L, 
66905L, 26905085L, 4098L, 0L, 14L, 88L, 530L, 97809006L, 90L, 
6L, 260792844L, 9L, 833205723L, 99467321L, 5L, 8455640L, 54090L, 
2L, 309L, 299161148L, 4952L, 454824L, 729805154L), Delta.Freq = c(5L, 
78L, 88553L, 794L, 5L, 3859122L, 782L, 36L, 8756801L, 243169338L, 
817789L, 8792384L, 7431L, 626921743L, 9206L, 95789L, 7916L, 8143453L, 
6L, 4L, 6363L, 181125L, 259618L, 6751L, 33L, 37960L, 0L, 2L, 
599582228L, 565585L, 19L, 48L, 269450424L, 70676581L, 7830566L, 
4L, 86484313L, 21L, 90899794L, 2L, 72356L, 574280L, 869544L, 
73418L, 6468164L, 2259L, 5938505L, 31329L, 1249L, 354L, 8817L, 
3L, 2568L, 82809L, 29836269L, 5230L, 37L, 33752014L, 79307L, 
1736L, 8522076L, 40L, 2289135L, 862L, 801448L, 8026L, 5L, 15L, 
4393771L, 405914L, 71098L, 950288L, 8319L, 1396973L, 832L, 70L, 
1746L, 61907L, 8709547L, 300750537L, 45862L, 91417085L, 79892L, 
47765L, 5477L, 18L, 4186L, 2860L, 754038591L, 375L, 53809223L, 
72L, 136L, 509L, 232325L, 13128104L, 1692L, 8581L, 23L, 7L), 
    Delta.Time = c(1361082L, 7926L, 499L, 5004L, 3494530L, 213L, 
    64551179L, 70L, 797L, 5L, 72588L, 86976L, 5163L, 635080L, 
    3L, 91L, 919806257L, 81443L, 3135427L, 4410972L, 5810L, 8L, 
    46603718L, 422L, 1083626L, 48L, 15699890L, 7L, 90167635L, 
    446459879L, 2332071L, 761660L, 49218442L, 381L, 46L, 493197L, 
    46L, 798597155L, 45342274L, 6265842L, 6L, 3445819L, 351L, 
    1761227L, 214L, 959L, 908996387L, 6L, 3855L, 9096604L, 152664L, 
    7970052L, 32366926L, 31L, 5201618L, 114L, 7806411L, 70L, 
    239L, 5065L, 2L, 1L, 14472831L, 122042249L, 8L, 495604L, 
    29L, 8965478L, 2875L, 959L, 39L, 9L, 690L, 933626665L, 85294L, 
    580093L, 95934L, 982058L, 65244056L, 137508L, 29L, 7621L, 
    7527L, 72L, 2L, 315L, 6L, 2413L, 8625150L, 51298109L, 851L, 
    890460L, 160736L, 6L, 850842734L, 2L, 7L, 76969113L, 190536L, 
    7855L), Peak.Time = c(1465265L, 452894L, 545076172L, 8226275L, 
    5040875L, 700530L, 1L, 3639L, 20141L, 71712131L, 686L, 923L, 
    770569738L, 69961L, 737458636L, 122403L, 199502046L, 6108L, 
    907L, 108078263L, 7817L, 4L, 6L, 69L, 721L, 786353L, 87486L, 
    1563L, 876L, 47599535L, 79295722L, 53L, 7378L, 591L, 6607935L, 
    954L, 6295L, 75514344L, 5742050L, 25647276L, 449L, 328566184L, 
    4L, 2L, 2703L, 21367543L, 63429043L, 708L, 782L, 909820L, 
    478L, 50L, 922L, 579882L, 7850L, 534L, 2157492L, 96L, 6L, 
    716L, 5L, 653290336L, 447854237L, 2L, 31972263L, 645L, 7L, 
    609909L, 4054695L, 455631L, 4919894L, 9L, 72713L, 9997L, 
    84090765L, 89742L, 5L, 5028L, 4126L, 23091L, 81L, 239635020L, 
    3576L, 898597785L, 6822L, 3798L, 201999L, 19624L, 20432923L, 
    18944093L, 930720236L, 1492302L, 300122L, 143633L, 5152743L, 
    417344L, 813L, 55792L, 78L, 14203776L), Center_Freq = c(61907L, 
    8709547L, 300750537L, 45862L, 91417085L, 79892L, 47765L, 
    5477L, 18L, 4186L, 2860L, 754038591L, 375L, 53809223L, 72L, 
    136L, 4700783L, 4173830L, 30L, 811L, 341014L, 780L, 44749L, 
    91L, 201620707L, 74L, 1L, 65422L, 595L, 89093186L, 946520L, 
    6940919L, 48744L, 2317845L, 5126197L, 2445L, 8L, 557450L, 
    450259742L, 21006647L, 9L, 7234027L, 59L, 9L, 651547554L, 
    45554L, 38493L, 91055218L, 38L, 1116474L, 2295482L, 3001L, 
    9L, 3270L, 141L, 53644L, 667983L, 565598L, 84L, 971L, 555498297L, 
    60431L, 6597L, 856943893L, 607815536L, 4406L, 79L, 4885076L, 
    745L, 8L, 56456L, 125140L, 73043989L, 516476L, 7L, 4440739L, 
    754038591L, 375L, 53809223L, 72L, 136L, 509L, 232325L, 13128104L, 
    1692L, 8581L, 23L, 5874213L, 4550L, 644668065L, 3712371L, 
    5928L, 8833L, 7L, 2186023L, 61627221L, 37297L, 716427989L, 
    21387L, 26639L), Start.Freq = c(426355L, 22073538L, 680374L, 
    41771L, 54L, 6762844L, 599171L, 108L, 257451851L, 438814L, 
    343045L, 4702L, 967787L, 1937L, 18L, 89301735L, 366L, 90L, 
    954L, 7337732L, 70891703L, 4139L, 10397931L, 940000382L, 
    7L, 38376L, 878528819L, 6287L, 738366L, 31L, 47L, 5L, 6L, 
    77848L, 2366508L, 45L, 3665842L, 7252260L, 6L, 61L, 3247L, 
    448348L, 1L, 705132L, 144L, 7423637L, 2L, 497L, 844927639L, 
    78978L, 914L, 131L, 7089563L, 927L, 9595581L, 2774463L, 1651L, 
    73509280L, 7L, 35L, 18L, 96L, 1L, 92545512L, 27354947L, 7556L, 
    65019L, 7480L, 71835L, 8249L, 64792L, 71537L, 349389666L, 
    280244484L, 82L, 6L, 40L, 353872L, 0L, 103L, 1255L, 4752L, 
    29L, 76L, 81185L, 14L, 9L, 470775630L, 818361265L, 57947209L, 
    44L, 24L, 41295L, 4L, 261449L, 9931404L, 773556640L, 930717L, 
    65007421L, 341175L), End.Freq = c(71000996L, 11613579L, 71377155L, 
    1942738L, 8760748L, 79L, 455L, 374L, 8L, 5L, 2266932L, 597833L, 
    155488L, 3020L, 4L, 554L, 4L, 16472L, 1945649L, 668181101L, 
    649780L, 22394365L, 93060602L, 172146L, 20472L, 23558847L, 
    190513L, 22759044L, 44L, 78450L, 205621181L, 218L, 69916344L, 
    23884L, 66L, 312148L, 7710564L, 4L, 422L, 744572L, 651547554L, 
    45554L, 38493L, 91055218L, 38L, 1116474L, 2295482L, 3001L, 
    9L, 3270L, 141L, 55595L, 38451L, 8660867L, 14L, 96L, 345L, 
    6L, 44L, 8235824L, 910517L, 1424326L, 87102566L, 53644L, 
    667983L, 565598L, 84L, 971L, 555498297L, 60431L, 6597L, 856943893L, 
    607815536L, 4406L, 79L, 7L, 28978746L, 7537295L, 6L, 633L, 
    345860066L, 802L, 1035131L, 602L, 2740L, 8065L, 61370968L, 
    429953765L, 981507L, 8105L, 343787257L, 44782L, 64184L, 12981359L, 
    123367978L, 818775L, 123745614L, 25345654L, 3L, 800889L), 
    Species = c("Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
    "Truncatus_Tursiops", "Truncatus_Tursiops", "Delphinus_Delphinus", 
    "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
    "Delphinus_Delphinus"), Country = c("Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
    "Holland", "Holland", "Holland", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France", "France", "France", "France", "France", 
    "France", "France")), class = "data.frame", row.names = c(NA, 
-100L))

这能满足您的需求吗? (如果你滚动到底部 :))。它将上一期的答案与 group_by 相结合,从 pivot_longer 中排除了 Countryn,并且还重命名了 Center_Freq 以便在旋转时正确命名。

library(tidyverse)

Dummy <- structure(list(ID = 1:100, Low.Freq = c(435L, 94103292L, 1L, 
                                        2688L, 8471L, 28818L, 654755585L, 468628164L, 342491L, 2288474L, 
                                        3915L, 411L, 267864894L, 3312618L, 5383L, 8989443L, 1894L, 534981L, 
                                        9544861L, 3437614L, 475386L, 7550764L, 48744L, 2317845L, 5126197L, 
                                        2445L, 8L, 557450L, 450259742L, 21006647L, 9L, 7234027L, 59L, 
                                        9L, 605L, 9199L, 3022L, 30218156L, 46423L, 38L, 88L, 396396244L, 
                                        28934316L, 7723L, 95688045L, 679354L, 716352L, 76289L, 332826763L, 
                                        6L, 90975L, 83103577L, 9529L, 229093L, 42810L, 5L, 18175302L, 
                                        1443751L, 5831L, 8303661L, 86L, 778L, 23947L, 8L, 9829740L, 2075838L, 
                                        7434328L, 82174987L, 2L, 94037071L, 9638653L, 5L, 3L, 65972L, 
                                        0L, 936779338L, 4885076L, 745L, 8L, 56456L, 125140L, 73043989L, 
                                        516476L, 7L, 4440739L, 612L, 3966L, 8L, 9255L, 84127L, 96218L, 
                                        5690L, 56L, 3561L, 78738L, 1803363L, 809369L, 7131L, 0L, 35502443L
), High.Freq = c(6071L, 3210L, 6L, 7306092L, 6919054L, 666399L, 
                 78L, 523880161L, 4700783L, 4173830L, 30L, 811L, 341014L, 780L, 
                 44749L, 91L, 201620707L, 74L, 1L, 65422L, 595L, 89093186L, 946520L, 
                 6940919L, 655350L, 4L, 6L, 618L, 2006697L, 889L, 1398L, 28769L, 
                 90519642L, 984L, 0L, 296209525L, 487088392L, 5L, 894L, 529L, 
                 5L, 99106L, 2L, 926017L, 9078L, 1L, 21L, 88601017L, 575770L, 
                 48L, 8431L, 194L, 62324996L, 5L, 81L, 40634727L, 806901520L, 
                 6818173L, 3501L, 91780L, 36106039L, 5834347L, 58388837L, 34L, 
                 3280L, 6507606L, 19L, 402L, 584L, 76L, 4078684L, 199L, 6881L, 
                 92251L, 81715L, 40L, 327L, 57764L, 97668898L, 2676483L, 76L, 
                 4694L, 817120L, 51L, 116712L, 666L, 3L, 42841L, 9724L, 21L, 4L, 
                 359L, 2604L, 22L, 30490L, 5640L, 34L, 51923625L, 35544L, 59644L
), Peak.Freq = c(87005561L, 9102L, 994839015L, 42745869L, 32840L, 
                 62737133L, 2722L, 24L, 67404881L, 999242982L, 3048L, 85315406L, 
                 703037627L, 331264L, 8403609L, 3934064L, 50578953L, 370110665L, 
                 3414L, 12657L, 40L, 432L, 7707L, 214L, 68588962L, 69467L, 75L, 
                 500297L, 704L, 1L, 102659072L, 60896923L, 4481230L, 94124925L, 
                 60164619L, 447L, 580L, 8L, 172L, 9478521L, 20L, 53L, 3072127L, 
                 2160L, 27301893L, 8L, 4263L, 508L, 712409L, 50677L, 522433683L, 
                 112844L, 193385L, 458269L, 93578705L, 22093131L, 6L, 9L, 1690461L, 
                 0L, 4L, 652847L, 44767L, 21408L, 5384L, 304L, 721L, 651147L, 
                 2426L, 586L, 498289375L, 945L, 6L, 816L, 46207L, 39135L, 6621028L, 
                 66905L, 26905085L, 4098L, 0L, 14L, 88L, 530L, 97809006L, 90L, 
                 6L, 260792844L, 9L, 833205723L, 99467321L, 5L, 8455640L, 54090L, 
                 2L, 309L, 299161148L, 4952L, 454824L, 729805154L), Delta.Freq = c(5L, 
                                                                                   78L, 88553L, 794L, 5L, 3859122L, 782L, 36L, 8756801L, 243169338L, 
                                                                                   817789L, 8792384L, 7431L, 626921743L, 9206L, 95789L, 7916L, 8143453L, 
                                                                                   6L, 4L, 6363L, 181125L, 259618L, 6751L, 33L, 37960L, 0L, 2L, 
                                                                                   599582228L, 565585L, 19L, 48L, 269450424L, 70676581L, 7830566L, 
                                                                                   4L, 86484313L, 21L, 90899794L, 2L, 72356L, 574280L, 869544L, 
                                                                                   73418L, 6468164L, 2259L, 5938505L, 31329L, 1249L, 354L, 8817L, 
                                                                                   3L, 2568L, 82809L, 29836269L, 5230L, 37L, 33752014L, 79307L, 
                                                                                   1736L, 8522076L, 40L, 2289135L, 862L, 801448L, 8026L, 5L, 15L, 
                                                                                   4393771L, 405914L, 71098L, 950288L, 8319L, 1396973L, 832L, 70L, 
                                                                                   1746L, 61907L, 8709547L, 300750537L, 45862L, 91417085L, 79892L, 
                                                                                   47765L, 5477L, 18L, 4186L, 2860L, 754038591L, 375L, 53809223L, 
                                                                                   72L, 136L, 509L, 232325L, 13128104L, 1692L, 8581L, 23L, 7L), 
Delta.Time = c(1361082L, 7926L, 499L, 5004L, 3494530L, 213L, 
               64551179L, 70L, 797L, 5L, 72588L, 86976L, 5163L, 635080L, 
               3L, 91L, 919806257L, 81443L, 3135427L, 4410972L, 5810L, 8L, 
               46603718L, 422L, 1083626L, 48L, 15699890L, 7L, 90167635L, 
               446459879L, 2332071L, 761660L, 49218442L, 381L, 46L, 493197L, 
               46L, 798597155L, 45342274L, 6265842L, 6L, 3445819L, 351L, 
               1761227L, 214L, 959L, 908996387L, 6L, 3855L, 9096604L, 152664L, 
               7970052L, 32366926L, 31L, 5201618L, 114L, 7806411L, 70L, 
               239L, 5065L, 2L, 1L, 14472831L, 122042249L, 8L, 495604L, 
               29L, 8965478L, 2875L, 959L, 39L, 9L, 690L, 933626665L, 85294L, 
               580093L, 95934L, 982058L, 65244056L, 137508L, 29L, 7621L, 
               7527L, 72L, 2L, 315L, 6L, 2413L, 8625150L, 51298109L, 851L, 
               890460L, 160736L, 6L, 850842734L, 2L, 7L, 76969113L, 190536L, 
               7855L), Peak.Time = c(1465265L, 452894L, 545076172L, 8226275L, 
                                     5040875L, 700530L, 1L, 3639L, 20141L, 71712131L, 686L, 923L, 
                                     770569738L, 69961L, 737458636L, 122403L, 199502046L, 6108L, 
                                     907L, 108078263L, 7817L, 4L, 6L, 69L, 721L, 786353L, 87486L, 
                                     1563L, 876L, 47599535L, 79295722L, 53L, 7378L, 591L, 6607935L, 
                                     954L, 6295L, 75514344L, 5742050L, 25647276L, 449L, 328566184L, 
                                     4L, 2L, 2703L, 21367543L, 63429043L, 708L, 782L, 909820L, 
                                     478L, 50L, 922L, 579882L, 7850L, 534L, 2157492L, 96L, 6L, 
                                     716L, 5L, 653290336L, 447854237L, 2L, 31972263L, 645L, 7L, 
                                     609909L, 4054695L, 455631L, 4919894L, 9L, 72713L, 9997L, 
                                     84090765L, 89742L, 5L, 5028L, 4126L, 23091L, 81L, 239635020L, 
                                     3576L, 898597785L, 6822L, 3798L, 201999L, 19624L, 20432923L, 
                                     18944093L, 930720236L, 1492302L, 300122L, 143633L, 5152743L, 
                                     417344L, 813L, 55792L, 78L, 14203776L), Center_Freq = c(61907L, 
                                                                                             8709547L, 300750537L, 45862L, 91417085L, 79892L, 47765L, 
                                                                                             5477L, 18L, 4186L, 2860L, 754038591L, 375L, 53809223L, 72L, 
                                                                                             136L, 4700783L, 4173830L, 30L, 811L, 341014L, 780L, 44749L, 
                                                                                             91L, 201620707L, 74L, 1L, 65422L, 595L, 89093186L, 946520L, 
                                                                                             6940919L, 48744L, 2317845L, 5126197L, 2445L, 8L, 557450L, 
                                                                                             450259742L, 21006647L, 9L, 7234027L, 59L, 9L, 651547554L, 
                                                                                             45554L, 38493L, 91055218L, 38L, 1116474L, 2295482L, 3001L, 
                                                                                             9L, 3270L, 141L, 53644L, 667983L, 565598L, 84L, 971L, 555498297L, 
                                                                                             60431L, 6597L, 856943893L, 607815536L, 4406L, 79L, 4885076L, 
                                                                                             745L, 8L, 56456L, 125140L, 73043989L, 516476L, 7L, 4440739L, 
                                                                                             754038591L, 375L, 53809223L, 72L, 136L, 509L, 232325L, 13128104L, 
                                                                                             1692L, 8581L, 23L, 5874213L, 4550L, 644668065L, 3712371L, 
                                                                                             5928L, 8833L, 7L, 2186023L, 61627221L, 37297L, 716427989L, 
                                                                                             21387L, 26639L), Start.Freq = c(426355L, 22073538L, 680374L, 
                                                                                                                             41771L, 54L, 6762844L, 599171L, 108L, 257451851L, 438814L, 
                                                                                                                             343045L, 4702L, 967787L, 1937L, 18L, 89301735L, 366L, 90L, 
                                                                                                                             954L, 7337732L, 70891703L, 4139L, 10397931L, 940000382L, 
                                                                                                                             7L, 38376L, 878528819L, 6287L, 738366L, 31L, 47L, 5L, 6L, 
                                                                                                                             77848L, 2366508L, 45L, 3665842L, 7252260L, 6L, 61L, 3247L, 
                                                                                                                             448348L, 1L, 705132L, 144L, 7423637L, 2L, 497L, 844927639L, 
                                                                                                                             78978L, 914L, 131L, 7089563L, 927L, 9595581L, 2774463L, 1651L, 
                                                                                                                             73509280L, 7L, 35L, 18L, 96L, 1L, 92545512L, 27354947L, 7556L, 
                                                                                                                             65019L, 7480L, 71835L, 8249L, 64792L, 71537L, 349389666L, 
                                                                                                                             280244484L, 82L, 6L, 40L, 353872L, 0L, 103L, 1255L, 4752L, 
                                                                                                                             29L, 76L, 81185L, 14L, 9L, 470775630L, 818361265L, 57947209L, 
                                                                                                                             44L, 24L, 41295L, 4L, 261449L, 9931404L, 773556640L, 930717L, 
                                                                                                                             65007421L, 341175L), End.Freq = c(71000996L, 11613579L, 71377155L, 
                                                                                                                                                               1942738L, 8760748L, 79L, 455L, 374L, 8L, 5L, 2266932L, 597833L, 
                                                                                                                                                               155488L, 3020L, 4L, 554L, 4L, 16472L, 1945649L, 668181101L, 
                                                                                                                                                               649780L, 22394365L, 93060602L, 172146L, 20472L, 23558847L, 
                                                                                                                                                               190513L, 22759044L, 44L, 78450L, 205621181L, 218L, 69916344L, 
                                                                                                                                                               23884L, 66L, 312148L, 7710564L, 4L, 422L, 744572L, 651547554L, 
                                                                                                                                                               45554L, 38493L, 91055218L, 38L, 1116474L, 2295482L, 3001L, 
                                                                                                                                                               9L, 3270L, 141L, 55595L, 38451L, 8660867L, 14L, 96L, 345L, 
                                                                                                                                                               6L, 44L, 8235824L, 910517L, 1424326L, 87102566L, 53644L, 
                                                                                                                                                               667983L, 565598L, 84L, 971L, 555498297L, 60431L, 6597L, 856943893L, 
                                                                                                                                                               607815536L, 4406L, 79L, 7L, 28978746L, 7537295L, 6L, 633L, 
                                                                                                                                                               345860066L, 802L, 1035131L, 602L, 2740L, 8065L, 61370968L, 
                                                                                                                                                               429953765L, 981507L, 8105L, 343787257L, 44782L, 64184L, 12981359L, 
                                                                                                                                                               123367978L, 818775L, 123745614L, 25345654L, 3L, 800889L), 
Species = c("Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Grampus_griseus", "Grampus_griseus", "Grampus_griseus", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Truncatus_Tursiops", 
            "Truncatus_Tursiops", "Truncatus_Tursiops", "Delphinus_Delphinus", 
            "Delphinus_Delphinus", "Delphinus_Delphinus", "Delphinus_Delphinus", 
            "Delphinus_Delphinus"), Country = c("Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
                                                "Holland", "Holland", "Holland", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France", "France", "France", "France", "France", 
                                                "France", "France")), class = "data.frame", row.names = c(NA, 
                                                                                                          -100L))

#Function to calculate the coefficient of variation
cv <- function(x) 100*( sd(x)/mean(x))

Summary_Statistics <- Dummy[-1] %>% 
  rename(Center.Freq = Center_Freq) %>% 
  group_by(Country) %>% 
  summarise(across(where(is.numeric), .fns = 
                            list(Median = median,
                                 Mean = mean,
                                 nsum = sum,
                                 SD = sd,
                                 SE = ~sd(.)/sqrt(n()),
                                 Min = min,
                                 Max = max,
                                 q25 = ~quantile(., 0.25), 
                                 q75 = ~quantile(., 0.75), 
                                 CV = cv
                            )), n = n()) %>% 
  pivot_longer(-c(Country, n), names_sep = "_", names_to = c( "variable", ".value"))

Summary_Statistics
#> # A tibble: 18 × 13
#>    Country     n variable Median   Mean   nsum     SD     SE   Min    Max    q25
#>    <chr>   <int> <chr>     <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <int>  <int>  <dbl>
#>  1 France     52 Low.Freq 2.78e4 4.03e7 2.10e9 1.52e8 2.10e7     0 9.37e8   80.8
#>  2 France     52 High.Fr… 2.00e3 1.98e7 1.03e9 7.98e7 1.11e7     0 4.87e8   38.5
#>  3 France     52 Peak.Fr… 4.61e3 5.37e7 2.79e9 1.59e8 2.20e7     0 8.33e8   84.8
#>  4 France     52 Delta.F… 4.19e4 4.55e7 2.36e9 1.41e8 1.96e7     0 7.54e8  120  
#>  5 France     52 Delta.T… 1.17e5 8.39e7 4.36e9 2.39e8 3.32e7     2 9.34e8  178. 
#>  6 France     52 Peak.Ti… 6.43e4 5.52e7 2.87e9 1.83e8 2.54e7     2 9.31e8 1411. 
#>  7 France     52 Center.… 5.71e4 7.25e7 3.77e9 1.94e8 2.69e7     1 7.54e8  574. 
#>  8 France     52 Start.F… 5.52e3 7.17e7 3.73e9 2.08e8 2.88e7     0 8.79e8   30.5
#>  9 France     52 End.Freq 5.28e5 7.79e7 4.05e9 1.84e8 2.55e7     3 8.57e8 2256. 
#> 10 Holland    48 Low.Freq 4.09e5 4.53e7 2.17e9 1.28e8 1.84e7     1 6.55e8 5016  
#> 11 Holland    48 High.Fr… 5.51e4 4.09e7 1.96e9 1.39e8 2.01e7     1 8.07e8  168. 
#> 12 Holland    48 Peak.Fr… 8.18e4 9.62e7 4.62e9 2.41e8 3.48e7     0 9.99e8 2000. 
#> 13 Holland    48 Delta.F… 8.42e3 2.04e7 9.81e8 9.61e7 1.39e7     3 6.27e8  675  
#> 14 Holland    48 Delta.T… 5.11e3 2.61e7 1.25e9 1.33e8 1.93e7     1 9.20e8   85.8
#> 15 Holland    48 Peak.Ti… 1.40e4 7.49e7 3.60e9 1.98e8 2.86e7     1 7.71e8  617. 
#> 16 Holland    48 Center.… 4.53e4 6.96e7 3.34e9 1.99e8 2.87e7     8 8.57e8  652. 
#> 17 Holland    48 Start.F… 6.49e4 5.14e7 2.47e9 1.83e8 2.63e7     1 9.40e8  810. 
#> 18 Holland    48 End.Freq 5.46e4 3.37e7 1.62e9 1.24e8 1.80e7     4 6.68e8  294  
#> # … with 2 more variables: q75 <dbl>, CV <dbl>

reprex package (v2.0.1)

于 2022-05-23 创建