如何在R中的函数中转换用户输入?
我正在尝试在R中开发一个UDF函数,该功能应该像这样起作用:
- 用户编写数学方程(例如 2*x + 4 )
- 我的函数应在R功能中转换输入并集成它具有下限/上限( 0和1 ),
因此,我的功能(2*x+4)必须解决此问题并显示5作为输出。
我尝试过的内容:
myfunction <- function(x, low, up) {
user_input <- function(x){}
res <- integrate(user_input, lower = low, upper = up)
return(res)
}
myfunction(2*x+4, low = 0, up = 1)
错误:
集成中的错误(user_input,下=低,upper = up): 功能的评估给出了错误长度
的结果
,我可以做以下操作:
integrand <- function(x){2*x+4}
integrate(integrand, lower = 0, upper = 1)
但这不是我想要的。
我会为一些提示感到非常高兴。
I am trying to develop a UDF function in R, which should work like this:
- user write a mathematical equation (eg 2*x + 4)
- My function should convert the input in a R-function and integrate it with lower/upper limits (0 and 1)
so, myfunction(2*x+4) have to solve this problem and show 5 as output.
What I've tried:
myfunction <- function(x, low, up) {
user_input <- function(x){}
res <- integrate(user_input, lower = low, upper = up)
return(res)
}
myfunction(2*x+4, low = 0, up = 1)
Error:
Error in integrate(user_input, lower = low, upper = up) :
evaluation of function gave a result of wrong length
sure, I could do the following:
integrand <- function(x){2*x+4}
integrate(integrand, lower = 0, upper = 1)
but thats not what I am looking for.
I would be very happy about some hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以进行
测试
We can do
-testing