You could use string manipulation functions to insert separators at the start and end of each group, then collapse everything into a single string (including the inserted breaks), and then split the groups up using the separators.
Using base-R
df1 <- data.frame(
V1 = tail(strsplit(paste(sub("^(>.*)", "\n\\1\n", df$V1), collapse = ""), "\n")[[1]], -1),
stringsAsFactors = FALSE
)
Explanation: sub()
matches values with ">" and inserts newlines before and after to separate each row group. paste()
combines everything into one string. strsplit()
breaks the string into separate values between the newlines and tail()
removes the extraneous empty group at the start.
The same steps, but spelled out a bit more clearly using dplyr
library(dplyr, warn.conflicts = FALSE)
df %>%
# Insert separators before and after groups
mutate(V1 = ifelse(grepl("^>", V1), paste0("\n", V1, "\n"), V1)) %>%
# Combine all groups into a single string
summarize(V1 = paste(V1, collapse = "")) %>%
# Split into groups using the separators
summarize(V1 = strsplit(V1, "\n")[[1]]) %>%
# drop the empty group at the beginning
filter(V1 != "")