I am searching for a simpler solution to the following problem. Here is my setup:
test <- tibble::tribble(
~group_name, ~id_name, ~varA, ~varB,
\"g
You can tabulate the the occurrence of id_name by group_name:
table(test$group_name,test$id_name)
If id_name is present in every group, we want columns that have all > 0 entris. We can simplify this logic using a combination of >0 and colMeans:
keep = names(which(colMeans(table(test$group_name,test$id_name)>0)==1))
Using this:
test[test$id_name %in% keep,]