小编Ste*_*eve的帖子

我怎样才能像purrr中的reduce2函数一样使用accumulate?

我想使用accumulate具有两个输入向量和reduce2函数的函数。的文档accumulate暗示可以给出两个输入向量并且accumulate可以与 一起使用reduce2。但是,我遇到了麻烦。

这是一个示例,灵感来自 的文档reduce2

这是来自的示例reduce2

> paste2 <- function(x, y, sep = ".") paste(x, y, sep = sep)
> letters[1:4] %>% reduce2(.y=c("-", ".", "-"), paste2)
[1] "a-b.c-d"
Run Code Online (Sandbox Code Playgroud)

accumulate这里有一些类似使用的尝试reduce2。没有一个能够正确地遍历letters[1:4]c("-",".","-")

> letters[1:4] %>% accumulate(.y=c("-", ".", "-"),paste2)
Error in .f(x, y, ...) : unused argument (.y = c("-", ".", "-"))

> letters[1:4] %>% accumulate(c("-", ".", "-"),paste2)
[[1]]
[1] "a"

[[2]]
NULL

> letters[1:4] …
Run Code Online (Sandbox Code Playgroud)

r purrr tidyverse

6
推荐指数
1
解决办法
774
查看次数

使用扫帚(增强)和dplyr与黄土适合时出错

我试图在黄土适合使用扩充,但我收到以下错误:

Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 32, 11
Run Code Online (Sandbox Code Playgroud)

在错误消息中,11恰好等于一个段中的观察数,32是观察总数.代码如下.

require(broom)
require(dplyr)

# This example uses the lm method and it works
regressions <- mtcars %>% group_by(cyl) %>%  do(fit = lm(wt ~ mpg, .))
regressions %>% augment(fit)

# This example uses the loess method and it generates the error
regressions2 <- mtcars %>% group_by(cyl) %>%  do(fit = loess(wt ~ mpg, .))
regressions2 %>% augment(fit)

# The below code appropriately plots the loess fit …
Run Code Online (Sandbox Code Playgroud)

r dplyr broom

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

标签 统计

r ×2

broom ×1

dplyr ×1

purrr ×1

tidyverse ×1