Если пусто, заполните Function
столбцы значением из предыдущей строки. И свернуть Title
, если Function
то же самое.
package_info_tbl$Function <- Reduce(function(x,y) if (y=="") x else y, package_info_tbl$Function, acc=T) %>%
package_info_tbl <- package_info_tbl %>%
group_by(Function) %>%
summarise(Title = paste(Title, collapse = " "))
Или объединить в вашу dplyr
цепочку
package_info_tbl <- package_info %>%
stringr::str_split(pattern = "\\s+", n = 2, simplify = T) %>%
tibble::as_tibble(.name_repair = "minimal") %>%
setNames(., c("Function", "Title")) %>%
mutate(Function = Reduce(function(x,y) if (y=="") x else y, Function, acc=T)) %>%
group_by(Function) %>%
summarise(Title = paste(Title, collapse = " ")) %>%
ungroup
Выход
package_info_tbl
# # A tibble: 12 x 2
# Function Title
# <chr> <chr>
# 1 %$% magrittr exposition pipe-operator
# 2 %<>% magrittr compound assignment pipe-operator
# 3 %>% magrittr forward-pipe operator
# 4 %T>% magrittr tee operator
# 5 [[.fseq Extract function(s) from a functional sequence.
# 6 debug_fseq Debugging function for functional sequences.
# 7 debug_pipe Debugging function for magrittr pipelines.
# 8 extract Aliases
# 9 freduce Apply a list of functions sequentially
# 10 functions Extract the function list from a functional sequence.
# 11 magrittr magrittr - Ceci n'est pas un pipe
# 12 print.fseq Print method for functional sequence.