Code
library(tidyverse)
library(digest)
library(plotly)
<- read.csv("data/score_in.csv")
data_before
<- read.csv("data/score_out.csv") data_after
Rui
December 24, 2023
对某地高新区内企业和高新区外规上工业企业的各指标得分的中位数进行比较
原始数据中包含企业名称,为了保密以及方便数据的展示,这里先对企业名称进行加密处理。加密方法参照上一节“哈希加密”。
值得注意的是 digest
好像不是向量化的函数,为了将每一个企业对的名称进行加密,应该配合 apply
函数使用:
data_before <- data_before %>%
mutate(企业名称 = apply(data_before["企业名称"],
MARGIN = 1,
FUN = function(name) {digest(name, algo = "sha256", serialize = FALSE)})
)
data_after <- data_after %>%
mutate(企业名称 = apply(data_after["企业名称"],
MARGIN = 1,
FUN = function(name) {digest(name, algo = "sha256", serialize = FALSE)})
)
data_after %>% head(10) %>% knitr::kable()
规上工业总产值总额 | 规上工业总产值增速 | 规上工业增加值总额 | 规上工业增加值增速 | 研发费用支出增速 | 研发费用支出强度 | 高新技术产业增加值占规上工业增加值比重 | 规上工业亩均增加值 | 全员劳动生产率 | 就业人员增长率 | 万元工业增加值能耗下降率 | 万元工业增加值二氧化碳排放量下降率 | 企业名称 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
63.92409 | 68.47692 | 68.95590 | 68.47692 | 63.64001 | 67.70703 | 100 | 63.70635 | 61.19254 | 61.09072 | 99.70356 | 99.70356 | 73d8d8e384fcd0e61e995cfe5bdb7312875100975a8ee4c99cf351f757a3586f |
60.56617 | 65.57963 | 60.40400 | 65.57963 | 60.68232 | 65.06278 | 100 | 60.20985 | 60.65121 | 60.51242 | 99.39421 | 99.39421 | 3ed4dbea5c309dd03bfadfef274fea77a82dd1a3def3c4ed3a8cd67ffc8be878 |
60.00000 | 60.00000 | 60.00000 | 60.00000 | 59.72703 | 60.00000 | 60 | 60.00000 | 60.00000 | 59.80861 | 60.00000 | 60.00000 | 7408a320379af65838ff99cf0601b0a0c720e670add8b1b945db2bf567302d12 |
114.29487 | 68.05926 | 190.27590 | 68.04467 | 65.53539 | 66.34880 | 100 | 68.05767 | 64.46792 | 61.11160 | 99.66804 | 99.66804 | 05767105719f061d5d920d22fd5bda0f97174c3b8de2cec12a813a790e99ed76 |
64.61384 | 67.44132 | 67.55096 | 67.44132 | 66.53583 | 73.54813 | 100 | 63.59536 | 60.60380 | 61.38499 | 99.54015 | 99.54015 | b3fedf4852917aebcc546efbf444612e0b5018ada2bbd66c63e120007b8a3dd7 |
60.27459 | 68.99321 | 60.44939 | 68.99321 | 60.51629 | 61.33653 | 60 | 60.37886 | 60.72438 | 60.31601 | 99.42003 | 99.42003 | 14fb126a5148c1eb8311874deb46687217199b3342c758244af1616b0f4949dd |
60.00000 | 60.00000 | 60.00000 | 60.00000 | 61.75928 | 100.00000 | 60 | 60.00000 | 60.00000 | 60.61809 | 100.00000 | 100.00000 | 1c0b4e218a3dfe019f0032565fb1f844fdcd5e3dfabc8e5e956be3c4f6c33886 |
60.68103 | 65.77052 | 61.52386 | 65.77052 | 65.07683 | 68.98019 | 60 | 61.13417 | 60.42427 | 61.04700 | 99.62890 | 99.62890 | 04c2ab54874b65535639117e2e26ea9a4a02bebd418884cc54bbaf64b63279ae |
61.10947 | 64.66320 | 62.05178 | 64.66320 | 63.12400 | 70.06770 | 100 | 61.25002 | 60.86080 | 60.98929 | 99.64441 | 99.64441 | 443efa1eb89c23e97de004b059e8c36945365c871da280498f8aba4921ca0079 |
60.42086 | 66.70817 | 60.42086 | 66.70817 | 60.00000 | 60.00000 | 100 | 61.12384 | 60.99149 | 60.95694 | 99.66189 | 99.66189 | 1a28eca2813ca9315847b8a02b1d77021e4e138cca6a0f8327b511bf2a1c93f6 |
有两种方法可以分别对各指标(每一列)求中位数:
mutate
加 across
同时对所有列操作data_before %>%
mutate(across(-企业名称, ~median(.)))
## 规上工业总产值总额 规上工业总产值增速 规上工业增加值总额 规上工业增加值增速
## 1 60.64169 65.73699 60.80333 65.66879
## 2 60.64169 65.73699 60.80333 65.66879
## 3 60.64169 65.73699 60.80333 65.66879
## 4 60.64169 65.73699 60.80333 65.66879
## 5 60.64169 65.73699 60.80333 65.66879
## 6 60.64169 65.73699 60.80333 65.66879
## 7 60.64169 65.73699 60.80333 65.66879
## 8 60.64169 65.73699 60.80333 65.66879
## 9 60.64169 65.73699 60.80333 65.66879
## 10 60.64169 65.73699 60.80333 65.66879
## 11 60.64169 65.73699 60.80333 65.66879
## 12 60.64169 65.73699 60.80333 65.66879
## 13 60.64169 65.73699 60.80333 65.66879
## 14 60.64169 65.73699 60.80333 65.66879
## 15 60.64169 65.73699 60.80333 65.66879
## 16 60.64169 65.73699 60.80333 65.66879
## 17 60.64169 65.73699 60.80333 65.66879
## 18 60.64169 65.73699 60.80333 65.66879
## 19 60.64169 65.73699 60.80333 65.66879
## 20 60.64169 65.73699 60.80333 65.66879
## 21 60.64169 65.73699 60.80333 65.66879
## 22 60.64169 65.73699 60.80333 65.66879
## 23 60.64169 65.73699 60.80333 65.66879
## 24 60.64169 65.73699 60.80333 65.66879
## 25 60.64169 65.73699 60.80333 65.66879
## 26 60.64169 65.73699 60.80333 65.66879
## 27 60.64169 65.73699 60.80333 65.66879
## 28 60.64169 65.73699 60.80333 65.66879
## 29 60.64169 65.73699 60.80333 65.66879
## 30 60.64169 65.73699 60.80333 65.66879
## 31 60.64169 65.73699 60.80333 65.66879
## 32 60.64169 65.73699 60.80333 65.66879
## 33 60.64169 65.73699 60.80333 65.66879
## 34 60.64169 65.73699 60.80333 65.66879
## 35 60.64169 65.73699 60.80333 65.66879
## 36 60.64169 65.73699 60.80333 65.66879
## 37 60.64169 65.73699 60.80333 65.66879
## 38 60.64169 65.73699 60.80333 65.66879
## 39 60.64169 65.73699 60.80333 65.66879
## 40 60.64169 65.73699 60.80333 65.66879
## 41 60.64169 65.73699 60.80333 65.66879
## 42 60.64169 65.73699 60.80333 65.66879
## 43 60.64169 65.73699 60.80333 65.66879
## 44 60.64169 65.73699 60.80333 65.66879
## 45 60.64169 65.73699 60.80333 65.66879
## 46 60.64169 65.73699 60.80333 65.66879
## 47 60.64169 65.73699 60.80333 65.66879
## 48 60.64169 65.73699 60.80333 65.66879
## 49 60.64169 65.73699 60.80333 65.66879
## 50 60.64169 65.73699 60.80333 65.66879
## 51 60.64169 65.73699 60.80333 65.66879
## 52 60.64169 65.73699 60.80333 65.66879
## 53 60.64169 65.73699 60.80333 65.66879
## 54 60.64169 65.73699 60.80333 65.66879
## 55 60.64169 65.73699 60.80333 65.66879
## 56 60.64169 65.73699 60.80333 65.66879
## 57 60.64169 65.73699 60.80333 65.66879
## 58 60.64169 65.73699 60.80333 65.66879
## 59 60.64169 65.73699 60.80333 65.66879
## 60 60.64169 65.73699 60.80333 65.66879
## 61 60.64169 65.73699 60.80333 65.66879
## 62 60.64169 65.73699 60.80333 65.66879
## 63 60.64169 65.73699 60.80333 65.66879
## 64 60.64169 65.73699 60.80333 65.66879
## 65 60.64169 65.73699 60.80333 65.66879
## 66 60.64169 65.73699 60.80333 65.66879
## 67 60.64169 65.73699 60.80333 65.66879
## 68 60.64169 65.73699 60.80333 65.66879
## 69 60.64169 65.73699 60.80333 65.66879
## 70 60.64169 65.73699 60.80333 65.66879
## 研发费用支出增速 研发费用支出强度 高新技术产业增加值占规上工业增加值比重
## 1 64.10647 71.45464 100
## 2 64.10647 71.45464 100
## 3 64.10647 71.45464 100
## 4 64.10647 71.45464 100
## 5 64.10647 71.45464 100
## 6 64.10647 71.45464 100
## 7 64.10647 71.45464 100
## 8 64.10647 71.45464 100
## 9 64.10647 71.45464 100
## 10 64.10647 71.45464 100
## 11 64.10647 71.45464 100
## 12 64.10647 71.45464 100
## 13 64.10647 71.45464 100
## 14 64.10647 71.45464 100
## 15 64.10647 71.45464 100
## 16 64.10647 71.45464 100
## 17 64.10647 71.45464 100
## 18 64.10647 71.45464 100
## 19 64.10647 71.45464 100
## 20 64.10647 71.45464 100
## 21 64.10647 71.45464 100
## 22 64.10647 71.45464 100
## 23 64.10647 71.45464 100
## 24 64.10647 71.45464 100
## 25 64.10647 71.45464 100
## 26 64.10647 71.45464 100
## 27 64.10647 71.45464 100
## 28 64.10647 71.45464 100
## 29 64.10647 71.45464 100
## 30 64.10647 71.45464 100
## 31 64.10647 71.45464 100
## 32 64.10647 71.45464 100
## 33 64.10647 71.45464 100
## 34 64.10647 71.45464 100
## 35 64.10647 71.45464 100
## 36 64.10647 71.45464 100
## 37 64.10647 71.45464 100
## 38 64.10647 71.45464 100
## 39 64.10647 71.45464 100
## 40 64.10647 71.45464 100
## 41 64.10647 71.45464 100
## 42 64.10647 71.45464 100
## 43 64.10647 71.45464 100
## 44 64.10647 71.45464 100
## 45 64.10647 71.45464 100
## 46 64.10647 71.45464 100
## 47 64.10647 71.45464 100
## 48 64.10647 71.45464 100
## 49 64.10647 71.45464 100
## 50 64.10647 71.45464 100
## 51 64.10647 71.45464 100
## 52 64.10647 71.45464 100
## 53 64.10647 71.45464 100
## 54 64.10647 71.45464 100
## 55 64.10647 71.45464 100
## 56 64.10647 71.45464 100
## 57 64.10647 71.45464 100
## 58 64.10647 71.45464 100
## 59 64.10647 71.45464 100
## 60 64.10647 71.45464 100
## 61 64.10647 71.45464 100
## 62 64.10647 71.45464 100
## 63 64.10647 71.45464 100
## 64 64.10647 71.45464 100
## 65 64.10647 71.45464 100
## 66 64.10647 71.45464 100
## 67 64.10647 71.45464 100
## 68 64.10647 71.45464 100
## 69 64.10647 71.45464 100
## 70 64.10647 71.45464 100
## 规上工业亩均增加值 全员劳动生产率 就业人员增长率 万元工业增加值能耗下降率
## 1 60.74138 60.68441 60.97039 99.57298
## 2 60.74138 60.68441 60.97039 99.57298
## 3 60.74138 60.68441 60.97039 99.57298
## 4 60.74138 60.68441 60.97039 99.57298
## 5 60.74138 60.68441 60.97039 99.57298
## 6 60.74138 60.68441 60.97039 99.57298
## 7 60.74138 60.68441 60.97039 99.57298
## 8 60.74138 60.68441 60.97039 99.57298
## 9 60.74138 60.68441 60.97039 99.57298
## 10 60.74138 60.68441 60.97039 99.57298
## 11 60.74138 60.68441 60.97039 99.57298
## 12 60.74138 60.68441 60.97039 99.57298
## 13 60.74138 60.68441 60.97039 99.57298
## 14 60.74138 60.68441 60.97039 99.57298
## 15 60.74138 60.68441 60.97039 99.57298
## 16 60.74138 60.68441 60.97039 99.57298
## 17 60.74138 60.68441 60.97039 99.57298
## 18 60.74138 60.68441 60.97039 99.57298
## 19 60.74138 60.68441 60.97039 99.57298
## 20 60.74138 60.68441 60.97039 99.57298
## 21 60.74138 60.68441 60.97039 99.57298
## 22 60.74138 60.68441 60.97039 99.57298
## 23 60.74138 60.68441 60.97039 99.57298
## 24 60.74138 60.68441 60.97039 99.57298
## 25 60.74138 60.68441 60.97039 99.57298
## 26 60.74138 60.68441 60.97039 99.57298
## 27 60.74138 60.68441 60.97039 99.57298
## 28 60.74138 60.68441 60.97039 99.57298
## 29 60.74138 60.68441 60.97039 99.57298
## 30 60.74138 60.68441 60.97039 99.57298
## 31 60.74138 60.68441 60.97039 99.57298
## 32 60.74138 60.68441 60.97039 99.57298
## 33 60.74138 60.68441 60.97039 99.57298
## 34 60.74138 60.68441 60.97039 99.57298
## 35 60.74138 60.68441 60.97039 99.57298
## 36 60.74138 60.68441 60.97039 99.57298
## 37 60.74138 60.68441 60.97039 99.57298
## 38 60.74138 60.68441 60.97039 99.57298
## 39 60.74138 60.68441 60.97039 99.57298
## 40 60.74138 60.68441 60.97039 99.57298
## 41 60.74138 60.68441 60.97039 99.57298
## 42 60.74138 60.68441 60.97039 99.57298
## 43 60.74138 60.68441 60.97039 99.57298
## 44 60.74138 60.68441 60.97039 99.57298
## 45 60.74138 60.68441 60.97039 99.57298
## 46 60.74138 60.68441 60.97039 99.57298
## 47 60.74138 60.68441 60.97039 99.57298
## 48 60.74138 60.68441 60.97039 99.57298
## 49 60.74138 60.68441 60.97039 99.57298
## 50 60.74138 60.68441 60.97039 99.57298
## 51 60.74138 60.68441 60.97039 99.57298
## 52 60.74138 60.68441 60.97039 99.57298
## 53 60.74138 60.68441 60.97039 99.57298
## 54 60.74138 60.68441 60.97039 99.57298
## 55 60.74138 60.68441 60.97039 99.57298
## 56 60.74138 60.68441 60.97039 99.57298
## 57 60.74138 60.68441 60.97039 99.57298
## 58 60.74138 60.68441 60.97039 99.57298
## 59 60.74138 60.68441 60.97039 99.57298
## 60 60.74138 60.68441 60.97039 99.57298
## 61 60.74138 60.68441 60.97039 99.57298
## 62 60.74138 60.68441 60.97039 99.57298
## 63 60.74138 60.68441 60.97039 99.57298
## 64 60.74138 60.68441 60.97039 99.57298
## 65 60.74138 60.68441 60.97039 99.57298
## 66 60.74138 60.68441 60.97039 99.57298
## 67 60.74138 60.68441 60.97039 99.57298
## 68 60.74138 60.68441 60.97039 99.57298
## 69 60.74138 60.68441 60.97039 99.57298
## 70 60.74138 60.68441 60.97039 99.57298
## 万元工业增加值二氧化碳排放量下降率
## 1 99.57298
## 2 99.57298
## 3 99.57298
## 4 99.57298
## 5 99.57298
## 6 99.57298
## 7 99.57298
## 8 99.57298
## 9 99.57298
## 10 99.57298
## 11 99.57298
## 12 99.57298
## 13 99.57298
## 14 99.57298
## 15 99.57298
## 16 99.57298
## 17 99.57298
## 18 99.57298
## 19 99.57298
## 20 99.57298
## 21 99.57298
## 22 99.57298
## 23 99.57298
## 24 99.57298
## 25 99.57298
## 26 99.57298
## 27 99.57298
## 28 99.57298
## 29 99.57298
## 30 99.57298
## 31 99.57298
## 32 99.57298
## 33 99.57298
## 34 99.57298
## 35 99.57298
## 36 99.57298
## 37 99.57298
## 38 99.57298
## 39 99.57298
## 40 99.57298
## 41 99.57298
## 42 99.57298
## 43 99.57298
## 44 99.57298
## 45 99.57298
## 46 99.57298
## 47 99.57298
## 48 99.57298
## 49 99.57298
## 50 99.57298
## 51 99.57298
## 52 99.57298
## 53 99.57298
## 54 99.57298
## 55 99.57298
## 56 99.57298
## 57 99.57298
## 58 99.57298
## 59 99.57298
## 60 99.57298
## 61 99.57298
## 62 99.57298
## 63 99.57298
## 64 99.57298
## 65 99.57298
## 66 99.57298
## 67 99.57298
## 68 99.57298
## 69 99.57298
## 70 99.57298
## 企业名称
## 1 5e592eb1be9c33ebf95d22a70e35a893fdf89237f59eeb6a3a8524d86e595221
## 2 b4fc790975fa3ece9fec53f6ff61eb9c616209d7be330a24bdeaaf08017da8d6
## 3 f16f14c14bde9473f26e36af3d83adecc10b70b7d95dbfac85819a5443c2afc6
## 4 805d37a1b01153a37811149b4c1ed14feff1d2bb68084e07b9d224f2cb235a0f
## 5 5a53ab418a8cc834f8ef56044445d42700d835887622d79960f570ae9d9fd857
## 6 389c41039eb24a9731fe1ff8e92d4a52125549b998a41e8005856933715de869
## 7 45dd8afd44cb8fd8a14ca81dbcd5ef3804ca9e045a9cd29ff9aa44eb1a2f8166
## 8 2fded1ede236998265d3a7427770c38d0166512977e4c017c4ea94a879ed2e46
## 9 968b7ce0a3684f627e54e690410812175df3fae3f81b1f04122a9f2d2e9d9ec9
## 10 42830a01ba3b1310122f4c5aff889a65cb64a7306c3614d1b122037932ce097c
## 11 b85cd6ee537821770492b9a494bedbd1009dc61b4cd803c8ac1d3cebb2b67759
## 12 fbf0097277a47a51b2e3b6b59e31799e648cf884fecf34dc33cb8a069efc398f
## 13 679bf2d4bfb7bfac7c022faa78291aeb57a70fc192c20d0f3ea76422ac955df5
## 14 745a5d7ebf54f97105dc204964af1ee3efe9dff57bacb8415cac7207f74978dd
## 15 315a0436930f116512e07d86f1836b0755ee5495bad6a8792606fe011215f3cb
## 16 d667e8337956629330dc76cf22a3506475cce63a923c29742b5150efff0b2930
## 17 e8e7cf149a9a49a53699f25f7098e8f19fe084f003bcfacc25b1afd91b510853
## 18 f9c0628030d620565f0bfdab429891ee82dc4697f910f65c567ef733a4ef634f
## 19 722b459d65dff8f4848be24ec6166bcf66218b9879cf57bc7937f14f64a86b4b
## 20 bf392277884fc04de7974a651c5b6d591164e4536c8e8c44cc3d57b4a2138c71
## 21 6b758f26db152257c85387f97c279f03b84107f21ff4e3b2bee7d0898db00a22
## 22 e8f88eb60fe065875dfcf84532d9fa320573c9ba009493839938e2c0401ff445
## 23 87b75ff280f1c47deab2f7c9cb4d61e08735a528d650d5bf7360c5225d9a021f
## 24 35ee84d108c075ea1bc0ac3312ab33ce7c8a27d29bf8a645e80fcd278c36faa7
## 25 05be7a82d3784e664edb70deea7572e33a234dddb728a23ebf7c41ce6d19edea
## 26 8ce10bd85ff526262ce09e4cf9669e9eacbe2dc7e3238c5b42b548f8014e92c6
## 27 59a98c5123c797cb4abf3291ee3513bbaa831649fdc11a05d801941c446b9647
## 28 13d1b4d8b2308bcf8897c23fdc02fbf058ff9f5a0788cb943843e16452571f28
## 29 6e2c8f806b5cf452f1423041a9e5e75935a92f6e11fb18aba3326b93d69afbf6
## 30 df94b6325ae8480646f9c7ee16b4865cc88658a1ab11b4e7f1de53d77b861f74
## 31 fd32114ac7806e64802c87388efa05b2655940941ff8e008b56a1a15eab89605
## 32 7cacbd121e1083ed8a669171594edebff94633dc45fac60be5e0d47886bf3392
## 33 2fed6c7694ad27ae8448abb5bd71cbf9d1930e7fafa3cbe4f26f51e3dd11d07d
## 34 66dd6be190e39534ab8e6060dcd0bcd925c33f9e455bbf357292f38c73b889ef
## 35 e19c0fe391b171657900095a9a073258e8623302deb4ffd5e92a6f93c6ae18ad
## 36 106c4396964784145883b49748eb2b70bc472978cec79add001fb24e3e7bccac
## 37 3aed676ba19fe63e6f746e82088c0876b36e5f07592e88cf0c10099c5fb7956c
## 38 f096d8bf942d3c59a63c4f6363abfe2b3c2ea7dbc3fc0d3029045a7331c438d6
## 39 fab4be0cbd5651868cb2851ec910e3df44824af219a81ae1727870b8b861e8f6
## 40 bfb13fca3592182bed9d33c754c622ea5a4568f0af916c8b1163058c15cacd55
## 41 1d93fab92f72f2ff323914e2e2afca08ab56151edc8a16f56a72dd310d806eee
## 42 b890e46df342ca959c36fc4442d43c805806d062ed6eb45b6b77fbfb27eab654
## 43 e88d0c7d6ac88c25f2a44ea645cd024d4285d93e6c994eb9789a2d5fd6974917
## 44 a2a4516b4e7eba0fa109ab1abd9089a7a9c9d24ddfd03d413ef0faa99072fb32
## 45 5f05d95129d6da62f5cfad61bce113bc046bc1887f1b14ec1e5594d42fa0a586
## 46 d1b4e83946103fda691b941608b3b7fe43a4c2612a12309a393754784cd407fd
## 47 c4f8e2ae88083bfadaf44b9ab80c4bc9de2976ef8959c529de6117b6493a900f
## 48 ed70bf3bbe6487cd1258163f3d31a8afd8371003faa7dd0a3f5ca9b3cc438aa2
## 49 712e92ce3eb3c4dcfb9b039e1334e7d4a92a25ceae3a9994d8baa553a207500b
## 50 e7c47c71e234a1d41bda3ccec622eb04038c3f5c1f720971d64d60e084c7d179
## 51 7d0cf33f8fc7469595173fb078b225212dbad6cc2192c637c0a4c73028ee3aee
## 52 0571a6a0e2a809a6ff7f5900123551c4b2180906995e00b46e0c18eea249e23b
## 53 0bcb2c4f9417a7c6a85008f3424d306e99df3054ce4d134955f3d5b83045cabd
## 54 e5b003254bae55fcda1cca9ea974a8909ac73b3957900eb74c2c440dba54257b
## 55 e031ec28e69a82f956a25bc8f1e7089bd3e8a3bcccba4bc6406de066fffd7f17
## 56 c0a12cfce3a5f74eee9fe3cf9f6d2ca1d19b983b6973e8ae849ca6bc71db3b18
## 57 5f4605832ed8605e318a1843ced3cea005ad9c9cd6c763b6a52681f38b80fbbc
## 58 ec59dd149464f0c70507651974fe7a1dfb7903859d81326f68b4ac52c7e5aa02
## 59 2da14337bad556a3ca7f2b93d9ae2c1935076ececb952d453fbc0d1441ab1d3a
## 60 5362546e8dc0681529c75af53227e4ddafbfbabf2a0867629a9e806e45c8f351
## 61 fa727b7d9b66c607d16e404f006abc20b2d926ffe4deb9b41e2012a6f90341a1
## 62 b8a338e32d7e3fdce689af313fca194bd40a3080d3e5f11bce4c8d4ecf41f205
## 63 1e63580d0acbb387aae8b9dc299c10aa09ac97cc50c2167fa844d8678a36b158
## 64 9873f41c74f1d4df1d1ab7973af9401c3c5ea4b8830e11bb93cfbb070d56c331
## 65 8480af5fb1123e2df8b7572f3a96f445f6987f424bec427e529bf7de3d0cef3e
## 66 a25b171ff0491b8952c7598d579c349e9df0cc347f46697792062f2075c4cafc
## 67 79f7cd0cbeb42097764e3fed95ed46a397d24e78e6881c3404cac1bf009c0c20
## 68 ae6db857dfcfeb5c4db1b9506f2aec2bb30bc6fc630f155f7efb5d2b37b87976
## 69 43e22c8f0a2dc0b1417c852ade44810584f55893a44293ae51a4830d0884a5fc
## 70 7f8102b7021c27eca2c6de3c19560e8a391c73a74d5ac2f01430438c11c0ec7c
apply
函数族data_before %>% select(-企业名称) %>%
apply(., MARGIN = 2, FUN = median)
## 规上工业总产值总额 规上工业总产值增速
## 60.64169 65.73699
## 规上工业增加值总额 规上工业增加值增速
## 60.80333 65.66879
## 研发费用支出增速 研发费用支出强度
## 64.10647 71.45464
## 高新技术产业增加值占规上工业增加值比重 规上工业亩均增加值
## 100.00000 60.74138
## 全员劳动生产率 就业人员增长率
## 60.68441 60.97039
## 万元工业增加值能耗下降率 万元工业增加值二氧化碳排放量下降率
## 99.57298 99.57298
我使用 lapply
函数加 purrr
包中的 map_dfr
函数进行函数式编程:
median_before <- data_before %>% select(-企业名称) %>%
lapply(., FUN = median) %>%
purrr::map_dfr(., ~.[1])
median_before
## # A tibble: 1 × 12
## 规上工业总产值总额 规上工业总产值增速 规上工业增加值总额 规上工业增加值增速
## <dbl> <dbl> <dbl> <dbl>
## 1 60.6 65.7 60.8 65.7
## # ℹ 8 more variables: 研发费用支出增速 <dbl>, 研发费用支出强度 <dbl>,
## # 高新技术产业增加值占规上工业增加值比重 <dbl>, 规上工业亩均增加值 <dbl>,
## # 全员劳动生产率 <dbl>, 就业人员增长率 <dbl>, 万元工业增加值能耗下降率 <dbl>,
## # 万元工业增加值二氧化碳排放量下降率 <dbl>
同样地,可以求出高新区外各指标得分的中位数:
状态 | 规上工业总产值总额 | 规上工业总产值增速 | 规上工业增加值总额 | 规上工业增加值增速 | 研发费用支出增速 | 研发费用支出强度 | 高新技术产业增加值占规上工业增加值比重 | 规上工业亩均增加值 | 全员劳动生产率 | 就业人员增长率 | 万元工业增加值能耗下降率 | 万元工业增加值二氧化碳排放量下降率 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
高新区内 | 60.64169 | 65.73699 | 60.80333 | 65.66879 | 64.10647 | 71.45464 | 100 | 60.74138 | 60.68441 | 60.97039 | 99.57298 | 99.57298 |
高新区外 | 60.68103 | 65.77052 | 61.52386 | 65.77052 | 63.12400 | 67.70703 | 100 | 61.13417 | 60.72438 | 60.98929 | 99.62890 | 99.62890 |
长宽转换,然后将数据整理成方便展示的形式:
median_data <- median_data %>% pivot_longer(cols = -状态, names_to = "指标", values_to = "值")
median_data <- inner_join(median_data %>% filter(状态 == "高新区内") %>% select(-状态) %>% rename("高新区内" = "值"),
median_data %>% filter(状态 == "高新区外") %>% select(-状态) %>% rename("高新区外" = "值"),
by = "指标")
median_data %>% knitr::kable()
指标 | 高新区内 | 高新区外 |
---|---|---|
规上工业总产值总额 | 60.64169 | 60.68103 |
规上工业总产值增速 | 65.73699 | 65.77052 |
规上工业增加值总额 | 60.80333 | 61.52386 |
规上工业增加值增速 | 65.66879 | 65.77052 |
研发费用支出增速 | 64.10647 | 63.12400 |
研发费用支出强度 | 71.45464 | 67.70703 |
高新技术产业增加值占规上工业增加值比重 | 100.00000 | 100.00000 |
规上工业亩均增加值 | 60.74138 | 61.13417 |
全员劳动生产率 | 60.68441 | 60.72438 |
就业人员增长率 | 60.97039 | 60.98929 |
万元工业增加值能耗下降率 | 99.57298 | 99.62890 |
万元工业增加值二氧化碳排放量下降率 | 99.57298 | 99.62890 |
布局调整:
从各指标的中位数来看,高新区内与高新区外的规上工业企业在大部分指标上的表现没有太大差别。高新区规上工业企业在研发费用支出强度上显著高于高新区外的规上工业企业。
---
title: "利用雷达图进行对比"
author: "Rui"
date: "2023-12-24"
categories: [R, plotly]
image: "chrysanthemum.jpg"
format:
html:
code-fold: true
code-tools: true
---
```{r setup, include = FALSE}
# 设置默认参数
knitr::opts_chunk$set(
echo = TRUE,
fig.align = "center",
message = FALSE,
warning = FALSE,
collapse = TRUE
)
```
对某地高新区内企业和高新区外规上工业企业的各指标得分的中位数进行比较
## 读取数据
```{r}
library(tidyverse)
library(digest)
library(plotly)
data_before <- read.csv("data/score_in.csv")
data_after <- read.csv("data/score_out.csv")
```
## 哈希加密脱敏
原始数据中包含企业名称,为了保密以及方便数据的展示,这里先对企业名称进行加密处理。加密方法参照上一节“哈希加密”。
值得注意的是 `digest` 好像不是向量化的函数,为了将每一个企业对的名称进行加密,应该配合 `apply` 函数使用:
```{r}
data_before <- data_before %>%
mutate(企业名称 = apply(data_before["企业名称"],
MARGIN = 1,
FUN = function(name) {digest(name, algo = "sha256", serialize = FALSE)})
)
data_after <- data_after %>%
mutate(企业名称 = apply(data_after["企业名称"],
MARGIN = 1,
FUN = function(name) {digest(name, algo = "sha256", serialize = FALSE)})
)
data_after %>% head(10) %>% knitr::kable()
```
## 计算各指标中位数
有两种方法可以分别对各指标(每一列)求中位数:
- 使用 `mutate` 加 `across` 同时对所有列操作
```{r}
data_before %>%
mutate(across(-企业名称, ~median(.)))
```
- 使用 `apply` 函数族
```{r}
data_before %>% select(-企业名称) %>%
apply(., MARGIN = 2, FUN = median)
```
我使用 `lapply` 函数加 `purrr` 包中的 `map_dfr` 函数进行函数式编程:
```{r}
median_before <- data_before %>% select(-企业名称) %>%
lapply(., FUN = median) %>%
purrr::map_dfr(., ~.[1])
median_before
```
同样地,可以求出高新区外各指标得分的中位数:
```{r}
median_after <- data_after %>% select(-企业名称) %>%
lapply(., FUN = median) %>%
purrr::map_dfr(., ~.[1])
median_data <- bind_rows(median_before, median_after) %>%
mutate(状态 = c("高新区内", "高新区外")) %>%
select(状态, everything())
median_data %>% knitr::kable()
```
长宽转换,然后将数据整理成方便展示的形式:
```{r}
median_data <- median_data %>% pivot_longer(cols = -状态, names_to = "指标", values_to = "值")
median_data <- inner_join(median_data %>% filter(状态 == "高新区内") %>% select(-状态) %>% rename("高新区内" = "值"),
median_data %>% filter(状态 == "高新区外") %>% select(-状态) %>% rename("高新区外" = "值"),
by = "指标")
median_data %>% knitr::kable()
```
## 雷达图对比
```{r}
p0 <- plot_ly(
type = "scatterpolar",
#fill = "toself",
mode = "lines"
)
p0
```
```{r}
p1 <- p0 %>%
add_trace(
r = median_data$高新区内,
theta = median_data$指标,
name = "高新区内",
fillcolor = rgb(166, 197, 193, 150, maxColorValue = 255),
line = list(color = rgb(166, 197, 193, 150, maxColorValue = 255), width = 3)
)
p1
```
```{r}
p2 <- p1 %>%
add_trace(
r = median_data$高新区外,
theta = median_data$指标,
name = "高新区外",
fillcolor = rgb(255, 135, 135, 200, maxColorValue = 255),
line = list(color = rgb(255, 135, 135, 200, maxColorValue = 255), width = 3)
)
p2
```
布局调整:
```{r}
p3 <- p2 %>%
layout(
polar = list(
radialaxis = list(
visible = TRUE,
range = c(20, 100),
tickvals = seq(20, 100, 10),
tickangle = 90
)
),
legend = list(
orientation = "h",
x = 0.4,
y = - 0.2
)
)
p3
```
从各指标的中位数来看,高新区内与高新区外的规上工业企业在大部分指标上的表现没有太大差别。高新区规上工业企业在研发费用支出强度上显著高于高新区外的规上工业企业。