Re: [R] help regarding loops in R

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Thu 04 Aug 2005 - 06:46:54 EST

Rangesh Kunnavakkam wrote:
> I have a large vector of around 12597 elements and I wish to calculate
> p-value for each element using a formula of something like:
> p-value= 1- exp^(kexp^(-labda))
> I was wondering someone could give some ideas how to implement for each element.
> thankyou very much
> Rangesh.K
>

Each element of what? lambda (sic), k? What are these? vectors, scalars? R is vectorised, so you should be able to do following, assuming lambda is a vector and k is a scalar, for example:

p <- 1 - exp(k * exp(-lambda))

(I am assuming I parsed your formula correctly. If not, please do clarify.)

If both k and lambda are both vectors then the above still applies as long as they are the same length (including length 1). If they differ in length, beware of R's recycling rules.

HTH, --sundar

P.S. Have you read the posting guide and subsequent literature, especially, an Introduction to R? Because you used "exp^(...)" and "kexp" suggests, no.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Aug 04 06:51:17 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:03:01 EST