## 手搓 myers index函数
calc_myers=function(V_ages){
sum(abs(table(as.factor(V_ages %% 10)) / length(V_ages) * 100 - 10))
}
## 测试数据
set.seed(42)
V_ages=sample(0:100,size=100,replace = TRUE)
V_ages
#> [1] 48 100 64 24 73 99 17 48 46 23 70 99 88 36 19 25 2 40
#> [19] 88 26 35 100 94 4 83 33 91 2 57 96 41 23 29 42 14 21
#> [37] 57 7 35 67 85 17 91 68 3 97 49 98 87 86 48 25 5 5
#> [55] 1 2 20 1 57 9 39 4 32 48 99 72 28 75 83 8 34 92
#> [73] 15 100 91 68 91 1 81 23 17 68 54 39 20 99 56 99 41 17
#> [91] 90 12 52 53 82 31 79 59 28 80
##计算myers index
calc_myers(V_ages)
#> [1] 18
<sup>Created on 2022-04-18 by the reprex package (v2.0.1)</sup>