It's hard to help without a better description of your data and an example of what the correct output would look like. That said, I think part of your confusion is due to the documentation in separate_rows
. A similar function, separate
, documents its sep
argument as:
If character, sep is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.
but the documentation for the sep
argument in separate_rows
doesn't say the same thing though I think it has the same behavior. In regular expressions, |
has special meaning so it must be escaped as \|
.
df <- tibble(
Inspection_ID = c(1, 2, 3),
Violations = c("A", "A|B", "A|B|C"))
separate_rows(df, Violations, sep = "\|")
Yields
# A tibble: 6 x 2
Inspection_ID Violations
<dbl> <chr>
1 1 A
2 2 A
3 2 B
4 3 A
5 3 B
6 3 C
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…