我有这样的小事 -
# A tibble: 11 × 1
messycol
<chr>
1 ""
2 ""
3 ""
4 ""
5 ""
6 ""
7 "|15|16|32|33|36|39|40|41|"
8 "|15|16|32|39|"
9 "|10|29|32|38|39|40|"
10 "|32|39|"
11 ""
输出dput()
在这里 -
structure(list(messycol = structure(c("", "", "", "", "", "",
"|15|16|32|33|36|39|40|41|", "|15|16|32|39|", "|10|29|32|38|39|40|",
"|32|39|", ""), label = "Noteffectiveaccountingrule reason keys", format.sas = "$")), row.names = c(NA,
-11L), class = c("tbl_df", "tbl", "data.frame"))
我想创建一个虚拟变量,如下所示messycol
- 如果messycol
包含 15 或 16,则为 1,否则为 0。请注意,中的空白值messycol
应保持原样 -" "
所以,我的预期输出是这样的 -
# A tibble: 11 × 2
messycol DUMMY
<chr>
1 "" ""
2 "" ""
3 "" ""
4 "" ""
5 "" ""
6 "" ""
7 "|15|16|32|33|36|39|40|41|" 1
8 "|15|16|32|39|" 1
9 "|10|29|32|38|39|40|" 0
10 "|32|39|" 0
11 "" ""