[R] efficient way to compute a probability distribution?

Antonio, Fabio Di Narzo antonio.fabio at gmail.com
Sat Aug 25 17:14:56 CEST 2007


prob <- function(x,ranks,dereg)
 mean(dereg %in% ranks[seq_len(x)])

2007/8/25, Naxerova, Kamila <Kamila_Naxerova a dfci.harvard.edu>:
> Hello!
>
> I have a piece of slow code and I am wondering if I am missing some obvious way
> to make it faster -- or if there is some predefined function I should be using
> instead.
>
> I have a list (ranks), for which I would like to compute the probability of a
> bunch of values (dereg) being contained in ranks[1:i]
>
> prob=function(x,ranks,dereg){
>
>         revranks=ranks[1:x]
>         p=length(which(dereg %in% revranks))/length(dereg)
>         return(p)
> }
>
> probdist=lapply(c(2:5166),prob,ranks=r,dereg=list)
>
> Takes a long time... too long to do a meaningful number of permutations.
>
> Thanks!!!
> --Kamila
>
>
> The information transmitted in this electronic communication...{{dropped}}
>
> ______________________________________________
> R-help a 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
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Antonio, Fabio Di Narzo
Ph.D. student at
Department of Statistical Sciences
University of Bologna, Italy



More information about the R-help mailing list