如何基于属性分配分组?

问题描述 投票:0回答:1

想象一下,我列出了51个角色,每个角色都有其6项技能固有的标准化价值。现在,我想知道是否存在一种可编程的方法来准确而平等地将这些人分配到平等的团队中,并牢记技能水平。我不确定哪种数据格式更合适,但是直觉上我认为较长的数据集将使其更容易:

df <- structure(list(unique_id = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 
7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 
12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 
16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 
18L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 
21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 
25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 
27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 
29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 
31L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 
34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 
36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 
38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L, 
40L, 40L, 40L, 41L, 41L, 41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 
42L, 42L, 43L, 43L, 43L, 43L, 43L, 43L, 44L, 44L, 44L, 44L, 44L, 
44L, 45L, 45L, 45L, 45L, 45L, 45L, 46L, 46L, 46L, 46L, 46L, 46L, 
47L, 47L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 48L, 48L, 49L, 
49L, 49L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 51L, 51L, 
51L, 51L, 51L, 51L), attribute = structure(c(2L, 1L, 3L, 4L, 
5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 
3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 
2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 
5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 
3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 
2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 
5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 
3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 
2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 5L, 6L, 2L, 1L, 3L, 4L, 
5L, 6L, 2L, 1L, 3L, 4L, 5L, 6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, 3, 4, 3, 2, 2, 2, 2, 0, 2, 2, 
2, 1, 2, 0, 0, 3, 3, 4, 3, 2, 3, 2, 1, 0, 3, 0, 2, 2, 1, 1, 2, 
1, 1, 2, 1, 1, 2, 0, 1, 2, 3, 3, 3, 2, 2, 2, 2, 1, 2, 1, 1, 2, 
1, 1, 2, 1, 1, 0, 1, 2, 2, 0, 2, 2, 1, 2, 2, 2, 2, 1, 1, 1, 2, 
1, 2, 1, 1, 1, 1, 1, 0, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1, 3, 
2, 2, 3, 0, 1, 3, 2, 3, 2, 3, 2, 1, 1, 1, 2, 0, 2, 2, 2, 2, 2, 
2, 1, 2, 2, 2, 2, 2, 0, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 
2, 2, 3, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 0, 2, 1, 2, 2, 
2, 1, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 4, 3, 3, 3, 2, 3, 2, 
2, 2, 3, 1, 2, 2, 3, 2, 3, 1, 3)), class = c("spec_tbl_df", "tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -306L))

[我的想法是以某种方式专注于每个技能组的运行平均值,但是我不知道从哪里开始。

也许,我使问题复杂化了,可以通过一组特定的分组和排序操作来解决。坦白说,我什至不知道如何搜索诸如此类的现有分配问题,这使我放慢了速度。

谢谢。

r optimization grouping subset permutation
1个回答
0
投票

您所描述的听起来像您想要进行聚类分析。这是一个使用kmeans聚类的方法,分为4组:

library(tidyr)
library(dplyr)
library(broom)

mat <- df %>% 
  pivot_wider(id_cols = unique_id, names_from = attribute, values_from = skill_level) %>%
  select(-unique_id)

clust <- kmeans(mat, 4)

df_new <- mat %>% 
  mutate(group = clust$cluster)

group_average <- clust %>% 
  tidy() %>% 
  rename(Communication = x1,
         Analytics = x2,
         Creativity = x3,
         "Problem solving" = x4,
         Programming = x5,
         "Project management" = x6)
group_average
#> # A tibble: 4 x 9
#>   Communication Analytics Creativity `Problem solvin~ Programming
#>           <dbl>     <dbl>      <dbl>            <dbl>       <dbl>
#> 1         2.11       1.94      2.22              2.33       1.94 
#> 2         2          1.22      0.944             2.22       0.667
#> 3         0.833      1.33      1.5               1          0.5  
#> 4         2.78       2.67      2.89              3          2.33 
#> # ... with 4 more variables: `Project management` <dbl>, size <int>,
#> #   withinss <dbl>, cluster <fct>
© www.soinside.com 2019 - 2024. All rights reserved.