unbreak_rows {unheadr} | R Documentation |
Merge rows up
unbreak_rows(df, regex, ogcol, sep = " ")
df |
A data frame with at least two contiguous rows to be merged. |
regex |
A regular expression to identify sets of rows to be merged, meant for the leading of the two contiguous rows. |
ogcol |
Variable with the text strings to match. |
sep |
Character string to separate the unified values (default is space). |
This function recodes empty strings ("") to NA
for smoother pattern matching.
A tibble or data frame with merged rows. Values of the lagging rows are pasted onto the values in the leading row, whitespace is squished, and the lagging row is dropped.
bball <-
data.frame(
stringsAsFactors = FALSE,
v1 = c(
"Player", NA, "Sleve McDichael", "Dean Wesrey",
"Karl Dandleton"
),
v2 = c("Most points", "in a game", "55", "43", "41"),
v3 = c("Season", "(year ending)", "2001", "2000", "2010")
)
unbreak_rows(bball, "Most", v2)