小编Fel*_*ana的帖子

在dplyr中保存管道之间的输出

我正在编写一个带有几个管道的函数.我想在最后一个管道之前将一些步骤保存为.tbl或数据框.例如:a %>% b %>% c,我想保存步骤'c',但也想要步骤'b'.

我知道一个选择是做两个管道,但我相信必须有更好的方法.

cars %>% mutate(kmh = dist/speed) %>% summary()

r pipe dplyr

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

有没有办法强制zoo :: rollmean函数返回一个与它的输入长度相同的向量?(或者可能使用其他功能?)

input = cbind(c(3,7,3,5,2,9,1,4,6,4,7,3,7,4))
library(zoo)
output = cbind(rollmean(input,4))
print(input)
print(output)
Run Code Online (Sandbox Code Playgroud)

输出:

      [,1]
 [1,]    3
 [2,]    7
 [3,]    3
 [4,]    5
 [5,]    2
 [6,]    9
 [7,]    1
 [8,]    4
 [9,]    6
[10,]    4
[11,]    7
[12,]    3
[13,]    7
[14,]    4
      [,1]
 [1,] 4.50
 [2,] 4.25
 [3,] 4.75
 [4,] 4.25
 [5,] 4.00
 [6,] 5.00
 [7,] 3.75
 [8,] 5.25
 [9,] 5.00
[10,] 5.25
[11,] 5.25
Run Code Online (Sandbox Code Playgroud)

但是当我试图解决它时:

Error in cbind(input, output) :
  number of rows of matrices must match (see arg 2)
Calls: print …
Run Code Online (Sandbox Code Playgroud)

r zoo

4
推荐指数
2
解决办法
4945
查看次数

标签 统计

r ×2

dplyr ×1

pipe ×1

zoo ×1