I got a vector of probabilities like,
probs<-c(0.001,0.5,0.02,1,.....)

Is there any nice and easy builtin function to get the number of
occurences within some specified probabality range.
Like with 2% it would be

occur[1] = sum(probs[probs>0&probs<0.02])
occur[2] = sum(probs[probs>0.02&probs<0.04])
...
occur[50] =sum(probs[probs>0.09] & probs<1)

(If it was a discrete space I would use 'table()' directly)

I made a function that looks something like
sorted <-sort(probs)
splits <- seq(0,1,0.02)

occur <- vector(mode="numeric",len=length(splits))
occur[1] <- sum(sorted<splits[2])

for(i in 2:(length(splits)-1))
   occur[i] <- sum(sorted<splits[i+1]) - sum(occur[1:i])

This seems to do what I want, but I guess there must be a more
beautifull way of doing it.

Thanks in advance

______________________________________________
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.

Reply via email to