[R] help regarding loops in R

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Aug 3 22:46:54 CEST 2005



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.




More information about the R-help mailing list