Допустим, у меня есть следующие данные
> summary_table[, c('condition_list', 'condition_count')]
# A tibble: 4,306 x 2
condition_list condition_count
<chr> <int>
1 true control,control email 2
2 true control,control email 1
3 treatment, control email 1
4 true control, control email 1
5 control email, true control 1
6 control email 1
7 control email, treatment 1
8 control email,true control 2
9 treatment 1
10 control email, true control 1
Обратите внимание, что столбец "condition_list" состоит из строк с ограничением запятыми, указывающих назначение некоторому условию, но некоторые из этих назначений изоморфны друг другу.Я хотел бы подсчитать количество строк в каждом условии следующим образом:
summary_table %>% group_by(condition_list) %>%
summarize(n= n())
Однако это будет рассматривать каждую конкретную комбинацию condition_list
как отдельную группу.Я хочу, чтобы это относилось к «контролю электронной почты, истинному контролю» так же, как «истинному контролю, контролю электронной почты».Каков наилучший способ сделать это?
> dput(dputter)
structure(list(condition_list = c("true control,control email",
"true control", "treatment", "true control", "control email",
"control email", "control email", "control email,true control",
"treatment", "control email", "true control,treatment", "treatment,true control",
"treatment,true control,control email", "control email", "treatment",
"true control,control email", "control email", "treatment", "true control,treatment",
"control email", "control email,true control", "treatment", "control email",
"control email", "control email,true control", "control email",
"control email", "true control", "treatment", "true control",
"treatment", "true control", "true control", "control email",
"true control", "control email", "control email", "true control",
"treatment", "treatment,true control,control email", "true control",
"true control", "treatment,control email", "true control", "true control",
"control email", "control email", "treatment", "control email",
"true control"), condition_count = c(2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 2L, 2L, 3L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 3L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -50L))