gpt4 book ai didi

r - 合并 tibble 中的行

转载 作者:行者123 更新时间:2023-12-03 14:00:20 24 4
gpt4 key购买 nike

我想在表格中列出我的包中的所有功能。

到目前为止,我从包帮助文档中提取了所有功能和标题

library(magrittr)
package_info <- library(help = magrittr)$info[[2]]
package_info_tbl <- package_info %>%
stringr::str_split(pattern = "\\s+", n = 2, simplify = T) %>%
tibble::as_tibble(.name_repair = "minimal")
colnames(package_info_tbl) <- c("Function", "Title")

package_info_tbl
#> # A tibble: 13 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
#> 11 "" sequence.
#> 12 "magrittr" magrittr - Ceci n'est pas un pipe
#> 13 "print.fseq" Print method for functional sequence.

创建于 2020-03-29 由 reprex package (v0.3.0)

我发现有些行是分开的,如果标题很长,会导致 2 行或更多行。如何合并这些行?

最佳答案

我们可以用 NA 替换空白值,使用 fill替换 NA以前的值在 Function专栏,group_by Function并为每个 Function 创建一个连接字符串.

library(dplyr)

package_info_tbl %>%
na_if('') %>%
tidyr::fill(Function) %>%
group_by(Function) %>%
summarise(Title = paste(Title, collapse = " "))


# A tibble: 12 x 2
# Function Title
# <chr> <chr>
# 1 [[.fseq Extract function(s) from a functional sequence.
# 2 %<>% magrittr compound assignment pipe-operator
# 3 %>% magrittr forward-pipe operator
# 4 %$% magrittr exposition pipe-operator
# 5 %T>% magrittr tee operator
# 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.

关于r - 合并 tibble 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60915509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com