hello all I am writing a quite simple script to study dental wear patterns in humans and I wrote this function sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this error message Error: attempt to apply non-function alternatively I wrote this sqrt(var(Y1)+var(Y2)^2)-4[(var(Y1)*(var(Y2)-cov(Y1,Y2)^2))] but this error message appear [1] NA Warning message: NAs introduced by coercion some suggestion to solve this?? thank you so much for your help Miguel [[alternative HTML version deleted]]
On 17-03-2013, at 16:47, Miguel Eduardo Delgado Burbano <mdelgadoburbano at gmail.com> wrote:> hello all > > I am writing a quite simple script to study dental wear patterns in humans > and I wrote this function > > sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this > error message > > Error: attempt to apply non-function >Write 4*( instead of 4( assuming you want to multiply.> alternatively I wrote this > sqrt(var(Y1)+var(Y2)^2)-4[(var(Y1)*(var(Y2)-cov(Y1,Y2)^2))] > > but this error message appear > > [1] NA > Warning message: > NAs introduced by coercion >[ is an indexing operator. You are trying to index the number 4. Which is impossible. Berend> some suggestion to solve this?? thank you so much for your help > > Miguel > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi, ?Y1<- 1:4 ?Y2<- 5:8 sqrt(var(Y1)+var(Y2)^2)-4*((var(Y1)*(var(Y2)-cov(Y1,Y2)^2))) #[1] 9.515593 A.K. ----- Original Message ----- From: Miguel Eduardo Delgado Burbano <mdelgadoburbano at gmail.com> To: r-help at r-project.org Cc: Sent: Sunday, March 17, 2013 11:47 AM Subject: [R] help with simple function hello all I am writing a quite simple script to study dental wear patterns in humans and I wrote this function sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this error message Error: attempt to apply non-function alternatively I wrote this sqrt(var(Y1)+var(Y2)^2)-4[(var(Y1)*(var(Y2)-cov(Y1,Y2)^2))] but this error message appear [1] NA Warning message: NAs introduced by coercion some suggestion to solve this?? thank you so much for your help Miguel ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hello, You are missing a '*' in your first try. (As for the second, in R parenthesis are round, not []) sqrt(var(Y1) + var(Y2))^2 - 4*(var(Y1)*(var(Y2) - cov(Y1, Y2)^2)) This written as a function becomes fun <- function(Y1, Y2) sqrt(var(Y1) + var(Y2))^2 - 4*(var(Y1)*(var(Y2) - cov(Y1, Y2)^2)) x1 <- rnorm(10) x2 <- rnorm(10) fun(x1, x2) Hope this helps, Rui Barradas Em 17-03-2013 15:47, Miguel Eduardo Delgado Burbano escreveu:> hello all > > I am writing a quite simple script to study dental wear patterns in humans > and I wrote this function > > sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this > error message > > Error: attempt to apply non-function > > alternatively I wrote this > sqrt(var(Y1)+var(Y2)^2)-4[(var(Y1)*(var(Y2)-cov(Y1,Y2)^2))] > > but this error message appear > > [1] NA > Warning message: > NAs introduced by coercion > > some suggestion to solve this?? thank you so much for your help > > Miguel > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >