在 dplyr 中保存管道之间的输出 [英] Save output between pipes in dplyr
本文介绍了在 dplyr 中保存管道之间的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个带有多个管道的函数.我想在最后一个管道之前将一些步骤保存为 .tbl 或数据框.例如:a %>% b %>% c
,我想保存步骤'c'
,但也想要步骤'b'
.
I am writing a function with several pipes. I would like to save some of the steps as .tbl or data frame before the last pipe. For instance: a %>% b %>% c
, I would like to save the step 'c'
, but also want the step 'b'
.
我知道一种选择是做两个管道,但我相信那一定有更好的方法.
I know that one option is to do two pipes, but I believe that must have a better way.
cars %>% mutate(kmh = dist/speed) %>% summary()
推荐答案
感谢您的帮助.我找到一个更好的解决方案,使用大括号{} 和 ->>.见下文
Thanks for the help. I found a better solution using braces{} and ->>. See below
c = cars %>% mutate(var1 = dist*speed)%>%
{. ->> b } %>% #here is save
summary()
c
head(b)
这篇关于在 dplyr 中保存管道之间的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文