[R] [FORGED] Recreate for loop without using for loop

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Mon Feb 11 05:37:29 CET 2019


This list has a "no homework" policy.

On 2/11/19 5:59 AM, Rima El-zein wrote:
> Hi.
> 
> 
> 
> Can someone please help me recreate this code without using a for loop? Idk if I'm supposed to use a map function or something else.

Supposed by whom?  What do you mean by "map function"?

> qprob <- function(pp) {
> 
>    qq <- 1 - pp -1
> 
>    stotal <- 0.0
> 
>    for (i in 1:length(pp))
> 
>      stotal <- stotal + pp[i] * prod(qq[-i])
> 
>    return(stotal)
> 
> }

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list