I have a data frame in R as shown below:
Group.ID status
1 1 open
2 1 open
3 2 open
4 2 closed
5 2 closed
6 3 open
I want to calculate the number of identifiers, provided that when all status is “open” for the same ID number. For example, the identifier of group 1 has two observations, and their status is “open”, so one for my account. Group 2 identifier is not because not all statuses are open for group 2 identifier.
I can read strings or group identifiers in conditions. However, I do not know how to apply the logic "all state equal to one value for the group."
DATA
df1 <-
structure(list(Group.ID = c(1, 1, 2, 2, 2, 3), status = structure(c(2L,
2L, 2L, 1L, 1L, 2L), .Label = c("closed", "open"), class = "factor")), .Names = c("Group.ID",
"status"), row.names = c(NA, -6L), class = "data.frame")
source
share