I am relatively new to R, so this may be a much simpler question than it seems to me. I am trying to create a function that includes two summations, and can't figure out how. I am attaching the equation as a pdf file. This function will then be optimized over a chosen range of values, but right now I just need help with the function. Thank you. Zack Darnell Duke University -- Zack Darnell Duke University Marine Lab 135 Duke Marine Lab Rd. Beaufort, NC 28516 Tel: (252) 732-5727 Email: mzd2 at duke.edu -------------- next part -------------- A non-text attachment was scrubbed... Name: equation.pdf Type: application/pdf Size: 10971 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/20071017/45109be4/attachment.pdf
Romain Francois
2007-Oct-17 12:35 UTC
[R] Need help with function that includes 2 summation
Zack Darnell wrote:> I am relatively new to R, so this may be a much simpler question than > it seems to me. I am trying to create a function that includes two > summations, and can't figure out how. I am attaching the equation as a > pdf file. This function will then be optimized over a chosen range of > values, but right now I just need help with the function. Thank you. > Zack Darnell > Duke UniversityHi, I'm a bit unsure of what you call double summation, I only see the i index in here, you can almost translate the latex code into R: R> sqrt( sum(cos(k*theta))^2 + sum(sin(k*theta))^2 ) / n theta being a vector containing all your theta_i, for i in 1 to n. Cheers, Romain -- Mango Solutions data analysis that delivers Tel: +44(0) 1249 467 467 Fax: +44(0) 1249 467 468 Mob: +44(0) 7813 526 123
Henrique Dallazuanna
2007-Oct-17 12:54 UTC
[R] Need help with function that includes 2 summation
Perhaps: r <- function(n, k, theta){ return(sqrt((sum(cos(k*theta))^2 + sum(sin(k*theta))^2)/n)) } On 17/10/2007, Zack Darnell <mzd2@duke.edu> wrote:> > I am relatively new to R, so this may be a much simpler question than it > seems to me. I am trying to create a function that includes two > summations, and can't figure out how. I am attaching the equation as a > pdf file. This function will then be optimized over a chosen range of > values, but right now I just need help with the function. Thank you. > Zack Darnell > Duke University > > -- > Zack Darnell > Duke University Marine Lab > 135 Duke Marine Lab Rd. > Beaufort, NC 28516 > > Tel: (252) 732-5727 > Email: mzd2@duke.edu > > > ______________________________________________ > R-help@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. > > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]