I am having a dataset that has a variable called individuals with many options and it comes like that. I have observations for a given Day on different individuals (Individual_ID)
The different options of individuals look like this: Individual_ID("Adele", "Fitz", "Abba").... these would belong to a group that is Group=A Individual_ID("Noir", "Rouge", "Bleue").... these would belong to a group called Group=B
In some instances, the individuals from different groups, can get mixed, so we have something like this Individual_ID("Adele", "Rouge", "Bleue")... so this would represent a mixed-group,
I would like to create a variable called GroupingID that can be either GroupA, GroupB, or MixedGroup For that I do not precise that all individuals of the group are present, but instead, that the representation of the individuals is neat or not neat with respect to their group.
为了考虑混合群体,涉及不同群体至少两个个人的任何组合都足够了。
难道有人能解释我如何运用一种条件和(或)相互交织的条件来形成一种可变的集团?
这里我的数据如何看待
Date IndividualsObserved
1/1/2016 Abba,Adele
2/1/2016 Adele,Fitz
3/1/2016 Fitz,Rouge,Noir
4/1/2016 Fitz,Adele,Abba
5/1/2016 Rouge,Noir,Bleue
6/1/2016 Rouge,Abba,Fitz
(不同个人在个人服务一栏的每个切身边)
So I would like to have a grouping category that is able to discern whether the grouping is neat (only one group identity, or whether the grouping is composed by a mixed of individuals from different groups). It would be something like this (GroupingID)
Date IndividualsObserved GroupingID
1/1/2016 Abba,Adele GroupA
2/1/2016 Adele,Fitz GroupA
3/1/2016 Fitz,Rouge,Noir MixedGrouping
4/1/2016 Fitz,Adele,Abba GroupA
5/1/2016 Rouge,Noir,Bleue GroupB
6/1/2016 Rouge,Abba,Fitz MixedGrouping
7/1/2016 Noir,Bleue,Abba MixedGrouping
我试图这样做,但并不奏效:
mutate(GroupingID = case_when(IndividualsObserved %in% c("Adele","Abba", "Fitz") ~ "GroupA",
IndividualsObserved %in% c("Noir","Bleue", "Rouge") ~ "GroupB",
TRUE ~ ToCheck))
谨请你就如何利用相互交错的选择来处理这一问题提出看法。
I Trial using dplyr function mut