将二进制变量转换为唯一组

时间:2018-09-05 14:39:58

标签: excel excel-formula

我有一个二进制变量(Var C),用于标识另一个变量(Var B)在不同变量(Var A)之上还是之下。通常,对于Var C,会有一系列相同的值。我想创建一个新变量(变量D),该变量代表两次开关之间的唯一数据组。

希望这会有所帮助

 VarA VarB VarC VarD
  30   28   1    1
  32   28   1    1
  33   30   1    1
  32   32   1    1
  34   33   1    1
  35   36   0    2
  37   38   0    2
  38   39   0    2
  39   39   0    2
  40   39   1    3
  38   37   1    3
  37   36   1    3
  35   33   1    3

在此先感谢您的帮助

2 个答案:

答案 0 :(得分:1)

如果您的数据在AC列中,则可以将值1分配给单元格D2,并对其余各行使用以下公式:

=IF(C3<>C2,D2+1,D2)

答案 1 :(得分:1)

D2 中输入 1

D3 中输入:

    <?php
    $array = '[
    {
    "competitorName": "Usain Bolt",
    "country": "Jamaica",
    "event": "100m",
    "medalWon": "G",
    "worldRecord": "Y"
    },
    {
    "competitorName": "Dave Batista",
    "country": "United States",
    "event": "Wrestling",
    "medalWon": "G",
    "worldRecord": "Y"
    },
    {
    "competitorName": "Leonel Messi",
    "country": "Argentina",
    "event": "Soccer \/ Football",
    "medalWon": "G",
    "worldRecord": "N"
    },
    {
    "competitorName": "Angel Di Maria",
    "country": "Argentina",
    "event": "Soccer \/ Football",
    "medalWon": "G",
    "worldRecord": "N"
    }
]';

$json = json_decode($array,true);
$countries = array_column($json, 'country'); // Get countries in to another array
// Then sort according to the names in above countries array ASC
call_user_func_array('array_multisort', array($countries, SORT_ASC, SORT_STRING, &$json)); 

print_r($json);
?>

并向下复制。

enter image description here