Learn R Programming

unheadr (version 0.4.0)

unbreak_rows: Merge rows up

Description

Merge rows up

Usage

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

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.

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

Details

This function recodes empty strings ("") to NA for smoother pattern matching.

Examples

Run this code
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)

Run the code above in your browser using DataLab