gpt4 book ai didi

r - 在 dplyr 包中找不到跨函数

转载 作者:行者123 更新时间:2023-12-04 11:33:46 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Error: could not find function ... in R

(10 个回答)


5 个月前关闭。




我想用across()函数在 dplyr但得到一个错误。例如,运行

iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), mean))
给我
Error in across(starts_with("Sepal"), mean) : 
could not find function "across"
across()是最近的介绍 https://towardsdatascience.com/what-you-need-to-know-about-the-new-dplyr-1-0-0-7eaaaf6d78acdplyr .但是,包 dplyr已更新并加载
packageVersion('dplyr')
[1] ‘1.0.0’
内部检查 dplyr
ls("package:dplyr")
[1] "%>%" "add_count" "add_count_" "add_row" "add_rownames" "add_tally"
[7] "add_tally_" "all_equal" "all_vars" "anti_join" "any_vars" "arrange"
[13] "arrange_" "arrange_all" "arrange_at" "arrange_if" "as_data_frame" "as_label"
我发现 across不存在,但是如果我在 helper 中查找该函数 ?across我得到了解释 across 功能的经典页面.
获取方式 across上类?
- - - 编辑 - - -
我的 sessionInfo()如下:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] tidyselect_1.1.0 dplyr_1.0.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 cellranger_1.1.0 pillar_1.4.2 compiler_3.6.1 forcats_0.4.0 tools_3.6.1 jsonlite_1.6 lubridate_1.7.4 lifecycle_0.2.0
[10] tibble_2.1.3 nlme_3.1-140 gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.3 rlang_0.4.6 cli_1.1.0 rstudioapi_0.10 haven_2.1.1
[19] xml2_1.2.2 httr_1.4.1 stringr_1.4.0 generics_0.0.2 vctrs_0.3.1 hms_0.5.1 grid_3.6.1 glue_1.4.1 R6_2.4.0
[28] fansi_0.4.0 readxl_1.3.1 readr_1.3.1 modelr_0.1.5 tidyr_1.0.0 purrr_0.3.3 ggplot2_3.2.1 magrittr_1.5 backports_1.1.4
[37] scales_1.0.0 rvest_0.3.4 assertthat_0.2.1 tidyverse_1.2.1 colorspace_1.4-1 utf8_1.1.4 stringi_1.4.3 lazyeval_0.2.2 munsell_0.5.0
[46] broom_0.5.2 crayon_1.3.4
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"

最佳答案

cross 功能仅在 dplyr 的开发版本中可用,在 CRAN 上尚不可用
使用accross功能安装dplyr dev版本通过使用下面的代码

install.packages("devtools")

library(devtools)
devtools::install_github("tidyverse/dplyr")
library(dplyr)
现在你的代码应该可以工作了
data("iris")
iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), mean))
输出
# A tibble: 3 x 3
Species Sepal.Length Sepal.Width
<fct> <dbl> <dbl>
1 setosa 5.01 3.43
2 versicolor 5.94 2.77
3 virginica 6.59 2.97

关于r - 在 dplyr 包中找不到跨函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62577775/

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