【发布时间】:2019-02-28 02:55:15
【问题描述】:
我有 3 列由指标 (0/1) 组成
icols <-
structure(list(delivery_group = c(0, 1, 1, 0, 0), culturally_tailored = c(0,
0, 1, 0, 1), integrated_intervention = c(1, 0, 0, 0, 0)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -5L))
我想返回一个单一的字符列“限定符”,这样带有指示符 == 1 的列名连接在一个字符串中,如下所示:
*qualifiers*
integrated_intervention
delivery_group
delivery_group, culturally_tailored
culturally_tailored
我尝试了 extdplyr::ind(使用各种选项)但没有成功。下面的一个使我的 R 会话崩溃。
icols <- extdplyr::ind_to_char(col = qualifiers, ret_factor = FALSE, remove = TRUE,
from = c("delivery_group", "culturally_tailored", "integrated_intervention"),
mutually_exclusive = FALSE, collectively_exhaustive = FALSE)
我找到了Convert Boolean indicator columns to a single factor column,但认为可能有更简单的解决方案。
【问题讨论】: