小编And*_*rew的帖子

在 dplyr 包中找不到跨函数

我想在其中使用该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()的如下: …

r dplyr across

7
推荐指数
1
解决办法
2099
查看次数

.External2(C_dataviewer, x, title) 中的错误:无法启动数据查看器

在 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 dataframe display

5
推荐指数
1
解决办法
2万
查看次数

安装 R 包 PearsonDS 会出现意外令牌错误

我在安装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)

linker r x86-64 clang token

5
推荐指数
1
解决办法
174
查看次数

R - 无法为 R 版本 3.6.2 安装“SDMTools”

我在安装 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)

installation r sdmtools

4
推荐指数
1
解决办法
5978
查看次数

在 R 中匹配多个没有循环的条件

我有一个显示一组条件的数据框,例如:

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非常大并且有很多条件,所以我想知道是否有办法在没有循环的情况下做同样的事情。谢谢你。

conditional loops r match dataframe

3
推荐指数
1
解决办法
3033
查看次数

标签 统计

r ×5

dataframe ×2

across ×1

clang ×1

conditional ×1

display ×1

dplyr ×1

installation ×1

linker ×1

loops ×1

match ×1

sdmtools ×1

token ×1

x86-64 ×1