如何按组为案例分配值

发布于 2025-02-11 04:55:39 字数 1824 浏览 2 评论 0原文

这是我正在使用的数据示例:

”在此处输入映像说明“

这是将数据分配到不同的文件中,一个由组划分为2个元素,而anothe anothe anothe anothe则具有3个元素,由3个元素

https://drive.google.com/drive.com/drive/five/five/folders/five/folders/13ncz1edrz7rj-1eppr=9-1eppr=9-rpfiv9-prfficr> 6.-w.-rpfiv9-wsknkejuls?

在列检查中,我想按组来掩盖此代码(组变量是代码,区域,地板和框)。

对于每个组组合:

  • 如果结果= 1,则情况= 1,另一个情况= 4,检查= 1 to case = 4,检查= 2 = 2 to结果= 1

  • 如果结果= 1,则在一个情况下= 1,另一个情况= 1 3,检查= 1 to case = 3,检查= 2 = 2 = 1

  • 如果结果= 1,则在一个情况下= 1,另一个情况= 1 1,检查= 1个情况,另一个检查= 2。

如何通过每个情况组对检查变量进行调整以在此图像中获得结果?

然后,我有每个组的案例:

https://i.sstatic.net/2migx.png“ alt =“在此处输入图像描述”>

对于每个组组合:

  • 如果结果= 1,则一个情况和其他两个都有结果= 4和结果= 4,检查= 1至第一个情况,结果= 4,第二个情况= 4 asign检查= 0,检查= 2 = 2 = 1 = 1

  • 如果结果= 1在一个情况下,另外两个的结果= 4,结果= 0,检查结果= 1,结果= 4,检查= 0 to case = 0,结果= 0,检查= 2至结果= 1

  • < p>如果结果= 1,在所有情况下,在其中一种情况下进行检查= 1,而另一个情况下的检查= 2,那么我们在下面的图像上看到的

“在此处输入图像描述”

我该如何做到这一点?

This is sample of data I am working with:

enter image description here

Here is the data splited into different files, one for 2 elements by group and anothe one with 3 elements by group

https://drive.google.com/drive/folders/13NcZ1eDRz7RfPIV0w-bOsF6kS1ePSQ9j?usp=sharing

In the column inspection I want to assing this codes by group (group variables are Code, Area, Floor and Box).

For each group combination:

  • If result=1 in one the cases and the other has result=4, inspection=1 to case with result=4 and inspection=2 to result=1

  • If result=1 in one the cases and the other has result=3, inspection=1 to case with result=3 and inspection=2 to result=1

  • If result=1 in one the cases and the other has result=1, inspection=1 one of the cases and to the other inspection=2.

How can I make this adjustment to inspection variable by each case groups to get the result in this image?

enter image description here

Then, I have cases with 3 elements per group:

enter image description here

For each group combination:

  • If result=1 in one the cases and the other two has result=4 and result=4, inspection=1 to first case with result=4, the second case with result=4 asign inspection=0 and inspection=2 to result=1

  • If result=1 in one the cases and the other two has result=4 and result=0, inspection=1 to the case with result=4, inspection=0 to case with result=0 and inspection=2 to result=1

  • If result=1 in all the cases, inspection=1 in one of the cases and to the other inspection=2, as we can see on the image below

enter image description here

How can I do that asignation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦屿孤独相伴 2025-02-18 04:55:39

如何仅使用结果重新安排c(2,1),例如:输出:

df %>% 
  group_by(Code, Area, Floor, Box) %>% 
  mutate(Inspection = c(2,1)[order(Result)])

输出:

  Code   Area Floor   Box Result Inspection
  <chr> <dbl> <dbl> <dbl>  <dbl>      <dbl>
1 10101    11   108     1      4          1
2 10101    11   108     1      1          2
3 10101    11    89     1      1          2
4 10101    11    89     1      1          1
5 10101    11    90     1      1          2
6 10101    11    90     1      3          1

How about just using the order of Result to rearrange c(2,1), like this:

df %>% 
  group_by(Code, Area, Floor, Box) %>% 
  mutate(Inspection = c(2,1)[order(Result)])

Output:

  Code   Area Floor   Box Result Inspection
  <chr> <dbl> <dbl> <dbl>  <dbl>      <dbl>
1 10101    11   108     1      4          1
2 10101    11   108     1      1          2
3 10101    11    89     1      1          2
4 10101    11    89     1      1          1
5 10101    11    90     1      1          2
6 10101    11    90     1      3          1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文