Skip to content
Prev 75189 / 398502 Next

vector vs array

General Notes :
a) Please try to give a simple example
b) Please avoid the rightwards assignment (i.e. "->"). Eventhough it is
perfectly legal to use it, it is confusing especially when you are
posting to a mailing list.


1) Here is a reproducible example

 set.seed(1)                         # for reproducibility
 v   <- abs( rnorm(1000) )
 thr <- c( 0.5, 1.0, 2.0, 3.0 )


2) If you simply want to count the number of points above a threshold

 sapply( thr, function(x) sum(v > x) )
 [1] 620 326  60   3


3) Or you can cut the data by threshold limits (be careful at the edges
if you have discrete data) followed by breaks

 table( cut( v, breaks=c( -Inf, thr, Inf ) ) ) )

 (-Inf,0.5]    (0.5,1]      (1,2]      (2,3]    (3,Inf]
        380        294        266         57          3

 
4) If you want to turn the problem on its head and ask for which
threshold point would you get 99%, 99.9% and 99.99% of the data below
it, you can use use quantiles

 quantile( v, c(0.99, 0.999, 0.9999) )
      99%    99.9%   99.99%
 2.529139 3.056497 3.734899


Regards, Adai
On Mon, 2005-08-08 at 08:34 -0700, alessandro carletti wrote: