使用dplyr管道命令进行数值计算 [英] Numeric calculations using dplyr piping commands

查看:108
本文介绍了使用dplyr管道命令进行数值计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用dplyr软件包中的管道进行数值计算?一个简单的例子是:

Is it possible to use piping from the dplyr package to do numeric calculations? A simple example is:

    0.15 %>% 3.8416 * (.*(1-.))/(0.03^2)  #does not work
    seq(1,10,1) %>% log(.) %>% .^2        #works

试图更多地了解管道的工作方式以及何时可以使用和不能使用管道.我真的很喜欢使用管道功能,并想找到一种将其用于这些类型的数值计算的方法.

Tying to understand more of how piping works and when it can and cannot be used. I really enjoy using the piping feature and want to find a way to use it for these types of numeric calculations.

非常感谢

推荐答案

您有一个运算符优先级问题.它正在尝试从做开始

You have an operator precedence problem. It's trying to start by doing

0.15 %>% 3.8416

这没有任何意义.您需要将所有计算分组到一个代码块中

which doesn't make sense. You need to group all your calculations in a code block

0.15 %>% {3.8416 * (.*(1-.))/(0.03^2)}

这篇关于使用dplyr管道命令进行数值计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆