Merge rows up

unbreak_rows(df, regex, ogcol, sep = " ")

Arguments

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).

Value

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.

Examples

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)
#> 1 match
#> v1 v2 v3 #> 1 Player Most points in a game Season (year ending) #> 2 Sleve McDichael 55 2001 #> 3 Dean Wesrey 43 2000 #> 4 Karl Dandleton 41 2010