Skip to contents

This function concatenates text spread across multiple rows based on a common key, using only base R functions.

Usage

gather_df_lines(
  df,
  key_colname,
  text,
  sep = "\\n",
  trimws = T,
  text_colname = "content"
)

Arguments

df

A data.frame containing the data

key_colname

character The column used as the grouping key (character string)

text

character The column containing the text to be concatenated (character string)

sep

character The separator used to concatenate the text (default is " ")

trimws

logical, default = TRUE If TRUE, suppress leading, tail and double white spaces

text_colname

character The colname for the concatened text column (default is "content")

Value

A data.frame with the text concatenated by key

Examples

# Create a sample data.frame
#df <- data.frame(id = c(1, 1, 1, 2, 2, 3),
# text = c("Hello ", "world ", " !", "How", "are    you?", " Test "))
# Use the function to concatenate text by 'id'
# gather_df_lines(df, key = "id", text = "text")