There is a data frame I want to subset the households that have member of specific ethnic group.
There are five main variables that need to consider.
- Variables (Number, Number_2, Number_3) are represent the households and have to group them.
- variable Ethnic represent the ethnic group.
- ** variable PERSNUM** represent the family or household member. e.g 1 is for husband, 2 is for wife, 3 is for first child, 4 is for second child , 5 is for father, 6 is for mother and so on.
I want to subset the data that households have the 11 ethnic group member. It could have one member or two and more or all of member of ethnic 11.
here is the sample of data:
df <- data.frame(
Village = c(rep("1", "30")),
Number = c(33, 33, 33, 33, 33, 33, 33, 1, 1, 30, 30, 30, 30, 30, 30, 30,
31, 31, 31, 31, 36, 36, 36, 36, 62, 62, 62, 62, 69, 69),
Number_1 = c(183, 183, 183, 183, 183, 183, 183, 151, 151, 255, 255, 255, 255, 255, 255,
255, 31, 31, 31, 31, 111, 111, 111, 111, 287, 287, 287,287, 219, 219),
Number_3 = c(137, 137, 137, 137, 137, 137, 137, 113, 113, 191, 191, 191, 191, 191, 191,
191, 23, 23, 23, 23, 83, 83, 83, 83, 215, 215, 215, 215, 164, 164),
PERSNUM = c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5, 6,
1, 2, 3, 1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 2),
Ethnic= c(33, 33, 33, 33, 33, 33, 33, 1, 1, 1, 1, 1, 1, 0, 11,
11, 11, 11, 11, 11, 0, 0, 11, 11, 11, 11, 11, 11, 11, 11))