如果两列具有相同的观察结果(分类和分类-1“),我正在尝试创建一个新列来检查组(id 和编号)。
这是原始数据框:
reprex <- tribble(~"id", ~"number", ~"year", ~"classification", ~"classification-1",
5, 7020, 2015, "Trading de servicios", "Servicios empresariales",
2, 4649, 2015, "Trading", "Comercial",
2, 4649, 2015, "Comercial", "Trading",
2, 4649, 2016, "Trading", "Comercial",
2, 4649, 2016, "Comercial", "Trading",
3, 4651, 2015, "Trading", "Comercial",
3, 4651, 2015, "Trading", "Comisiones",
3, 4651, 2015, "Comercial", "Trading",
3, 4651, 2015, "Comercial", "Comisiones")
我想得到这个:
reprex <- tribble(~"id", ~"number", ~"year", ~"classification", ~"classification-1", ~"check",
5, 7020, 2015, "Trading de servicios", "Servicios empresariales", T,
2, 4649, 2015, "Trading", "Comercial", T
2, 4649, 2015, "Comercial", "Trading", T
2, 4649, 2016, "Trading", "Comercial", T
2, 4649, 2016, "Comercial", "Trading", T
3, 4651, 2015, "Trading", "Comercial", F
3, 4651, 2015, "Trading", "Comisiones", F
3, 4651, 2015, "Comercial", "Trading", F
3, 4651, 2015, "Comercial", "Comisiones", F)