在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屋!
查看全文