我想在其中使用该across()
函数dplyr
但出现错误。例如,运行
iris %>%
group_by(Species) %>%
summarise(across(starts_with("Sepal"), mean))
Run Code Online (Sandbox Code Playgroud)
给我
Error in across(starts_with("Sepal"), mean) :
could not find function "across"
Run Code Online (Sandbox Code Playgroud)
across()
是最近的介绍https://towardsdatascience.com/what-you-need-to-know-about-the-new-dplyr-1-0-0-7eaaaf6d78ac in dplyr
. 但是,包dplyr
已更新并加载
packageVersion('dplyr')
[1] ‘1.0.0’
Run Code Online (Sandbox Code Playgroud)
检查内部 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"
Run Code Online (Sandbox Code Playgroud)
我发现它across
不存在,但是如果我在 helper 中查找该函数,?across
我会得到解释across
.
如何across
上班?
- - - 编辑 - - -
我sessionInfo()
的如下: …
在 RI 中,任何时候我都会遇到以下错误,View()
或者data.frame
我不明白为什么。它发生得很突然。
> View(Fhat_all)
Error in .External2(C_dataviewer, x, title) : unable to start data viewer
In addition: Warning message:
In View(Fhat_all) : unable to open display
> da <- data.frame(comb[true_comb_RMSE[1],1], comb[true_comb_RMSE[1],2],
comb[true_comb_KS[1],1],comb[true_comb_KS[1],2])
Error in (function (env, objName) :
could not find function "object.size"
Run Code Online (Sandbox Code Playgroud)
我在 Stackoverflow 中检查了另一个页面无法使用 View() 或 edit() 函数,收到“Error in .External2(C_dataviewer, x, title) : invalid device”错误消息,但我不明白如何修复它. 所以我点击locale
了终端并得到了这个结果:
Last login: Mon Mar 21 16:47:07 on ttys000
MacBook-Pro:~ "username"$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8" …
Run Code Online (Sandbox Code Playgroud) 我在安装R
包时遇到问题PearsonDS
。在 RStudio 中,我运行:
> install.packages("PearsonDS")
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6:
cannot open URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/PACKAGES'
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘PearsonDS’
Do you want to attempt to install these from sources? (Yes/no/cancel) Yes
installing the source package ‘PearsonDS’
trying URL 'https://cran.rstudio.com/src/contrib/PearsonDS_1.1.tar.gz'
Content type 'application/x-gzip' length 63798 bytes (62 KB)
==================================================
downloaded 62 KB
* installing *source* package ‘PearsonDS’ ...
** package ‘PearsonDS’ …
Run Code Online (Sandbox Code Playgroud) 我在安装 R 包时遇到问题SDMTools
。
install.packages("SDMTools")
Installing package into ‘C:/Users/aaa/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘SDMTools’ is not available (for R version 3.6.2)
Run Code Online (Sandbox Code Playgroud)
我也试过
BiocManager::install(c('SDMTools'), ask=T )
Bioconductor version 3.10 (BiocManager 1.30.10), R 3.6.2 (2019-12-12)
Installing package(s) 'SDMTools'
Installation path not writeable, unable to update packages: boot, foreign, lattice, MASS, nlme, nnet
Old packages: 'digest', 'mvtnorm'
Update all/some/none? [a/s/n]:
n
Warning message:
package ‘SDMTools’ is not available (for R version 3.6.2)
Run Code Online (Sandbox Code Playgroud)
我的会话信息如下:
sessionInfo()
R version 3.6.2 …
Run Code Online (Sandbox Code Playgroud) 我有一个显示一组条件的数据框,例如:
B = data.frame(col1 = 1:10, col2 = 11:20 )
Run Code Online (Sandbox Code Playgroud)
例如,第一行说当 col1 = 1 时,col2 = 11。我还有另一个数据框,其中的数字应该满足这些条件,例如:
A = data.frame(col1 = c(1:11,1:11), col2 = c(11:21,11:21), col3 = 101:122)
Run Code Online (Sandbox Code Playgroud)
我想为满足 B 中条件的所有行返回col3
矩阵中值的总和A
。例如,使用 B 中的第一行这个值是:
sum(A$col3[which(A$col1 == B$col1[1] & A$col2 == B$col2[1])])
#[1] 213
Run Code Online (Sandbox Code Playgroud)
即col3
第 1 行和第 12 行中条目的总和A
。我需要为 matrix 的所有行找到一个包含所有这些总和的向量A
。我知道如何用循环来做到这一点,但是在我的数据矩阵中A
并且B
非常大并且有很多条件,所以我想知道是否有办法在没有循环的情况下做同样的事情。谢谢你。