我试图在R studio中运行以下简单的功能
a<-testfunc15(state,outcome)
{
st<-state
out<-outcome
print(st)
tempdff<-healthcareoutcome[healthcareoutcome$State==st,]
tempdff
}
当我复制并粘贴R studio的R提示时,我收到错误:
Error: could not find function "testfunc15"
> {
+
+ st<-state
+ out<-outcome
+ print(st)
+ tempdff<-healthcareoutcome[healthcareoutcome$State==st,]
+ tempdff
+
+ }
Error: object 'state' not found
当我尝试采购它时:来源(&#34; testfunc15.R&#34;) 然后我得到这个错误:
Error in eval(expr, envir, enclos) : could not find function"testfunc15"
我将文件保存在与其他函数相同的getwd()中,其他函数正常工作。 我哪里错了? 虽然有很多相同描述的问题,但我无法在stackoverflow上找到答案。 请帮忙
答案 0 :(得分:2)
代码的第一行告诉R将testfunc15(state, outcome)
的结果存储在a
中。它没有定义函数。
此处所写的功能也不存在。正如Dason所提到的,它应该是:
testfunc15 = function (state, outcome)
或testfunc15 <- function (state, outcome)
最后可以是return(tempdiff)
或tempdiff