[R] Newbie on functions
Angelo Secchi
secchi at sssup.it
Mon Nov 7 19:10:32 CET 2005
Hi,
I'm trying to write a simple function like
case1 <- function (m, cov, Q, R) {
theta <- (acos(R/sqrt(Q^3)))
beta <- (-2)*sqrt(Q)*cos(theta/3)+m[1]/3
rho1 <- (-2)*sqrt(Q)*cos((theta+2*pi)/3)+m[1]/3
rho2 <- (-2)*sqrt(Q)*cos((theta-2*pi)/3)+m[1]/3
stderrb <- deltamethod( ~(-2)*sqrt(Q)*cos(theta/3)+x1/3,m,cov)
stderrr1 <- deltamethod( ~(-2)*sqrt(Q)*cos((theta+2*pi)/3)+x1/3, m,
cov) stderrr2 <- deltamethod( ~(-2)*sqrt(Q)*cos((theta-2*pi)/3)+x1/3,
m, cov) stderr <- c(stderrb,stderrr1,stderrr2)
results <- c(beta,rho1,rho2,stderr)
results2 <- t(results)
results2
}
When I call the function in an IF statement like
if (Q^3>R^2) results2 <- case1() else print('ciccio')
I get
Error in eval(expr, envir, enclos) : Object "theta" not found
I do not understand why, any help?
Thanks
--
========================================================
Angelo Secchi PGP Key ID:EA280337
More information about the R-help
mailing list