[R] Counting confidence intervals

Rui Barradas ruipbarradas at sapo.pt
Mon Mar 18 20:59:28 CET 2013


Hello,

There _is_ a function ?within. Maybe your function can be named 'between'

Rui Barradas

Em 18-03-2013 16:16, S Ellison escreveu:
>>> I want to cont how many
>>> times a number say 12 lies in the interval. Can anyone assist?
>
> Has anyone else ever wished there was a moderately general 'inside' or 'within' function in R for this problem?
>
> For example, something that behaves more or less like
>
> within <- function(x, interval=NULL, closed=c(TRUE, TRUE), lower=min(interval), upper=max(interval)) {
> 	#interval must be a length 2 vector
> 	#closed is taken in the order (lower, upper)
> 	#lower and upper may be vectors and will be recycled (by "<" etc) if not of length length(x)
>
> 	low.comp <- if(closed[1]) "<=" else "<"	
> 	high.comp <- if(closed[2]) ">=" else ">"
>
> 	do.call(low.comp, list(lower, x)) & do.call(high.comp, list(upper, x))
> }
>
>
> #Examples
> within(1:5, c(2,4))
>
> within(1:5, c(2,4), closed=c(FALSE, TRUE))
>
> within(1:5, lower=5:1, upper=10:14)
>
>
> S Ellison
> LGC
>
> *******************************************************************
> This email and any attachments are confidential. Any use...{{dropped:8}}
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list