An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130318/70fd78e9/attachment.pl>
Counting confidence intervals
11 messages · Jorge I Velez, Jeff Newmiller, Jim Silverton +5 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130319/02970650/attachment.pl>
sum(M[1]<12 & 12<=M[2]) untested, no data
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Jim Silverton <jim.silverton at gmail.com> wrote:
Hi, I have a 2 x 10000 matrix of confidence intervals. The first column is the lower and the next column is the upper. I want to cont how many times a number say 12 lies in the interval. Can anyone assist?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130318/1535f4ab/attachment.pl>
Hi, Try this: set.seed(25) mat1<- matrix(cbind(sample(1:15,20,replace=TRUE),sample(16:30,20,replace=TRUE)),ncol=2) ?nrow(mat1[sapply(seq_len(nrow(mat1)),function(i) any(seq(mat1[i,1],mat1[i,2])==12)),]) #[1] 17 set.seed(25) mat2<- matrix(cbind(sample(1:15,1e5,replace=TRUE),sample(16:30,1e5,replace=TRUE)),ncol=2) system.time(res<-nrow(mat2[sapply(seq_len(nrow(mat2)),function(i) any(seq(mat2[i,1],mat2[i,2])==12)),])) ?#? user? system elapsed ?# 1.552?? 0.000?? 1.549 res #[1] 80070 ?head(mat2[sapply(seq_len(nrow(mat2)),function(i) any(seq(mat2[i,1],mat2[i,2])==12)),]) #???? [,1] [,2] #[1,]??? 7?? 29 #[2,]?? 11?? 30 #[3,]??? 3?? 30 #[4,]??? 2?? 26 #[5,]?? 10?? 22 #[6,]??? 6?? 22 A.K.
From: Jim Silverton <jim.silverton at gmail.com>
To: r-help at r-project.org
Sent: Monday, March 18, 2013 9:03 AM
Subject: Re: [R] Counting confidence intervals
To: r-help at r-project.org
Sent: Monday, March 18, 2013 9:03 AM
Subject: Re: [R] Counting confidence intervals
Hi, I have a 2 x 10000 matrix of confidence intervals. The first column is the lower and the next column is the upper. I want to cont how many times a number say 12 lies in the interval. Can anyone assist?
Thanks, Jim. ??? [[alternative HTML version deleted]] ______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130319/9dc1a4c0/attachment.pl>
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}}
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.
There _is_ a function ?within.
Drat! of course there is. I even use it, though not often.
Maybe your function can be named 'between'
Good thought - thanks
Steve E
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130320/6cbcd75f/attachment.pl>
You should look at findInterval. Used with as.numeric it could do what you request although it has a much wider range of uses.
David
Sent from my iPhone
On Mar 20, 2013, at 5:15 PM, Greg Snow <538280 at gmail.com> wrote:
> The TeachingDemos package has %<% and %<=% functions that can be chained
> simply, so you could do something like:
>
> sum( 5:1 %<=% 1:5 %<=% 10:14 )
>
> and other similar approaches.
>
> The idea is that you can do comparisons as:
>
> lower %<% x %<% upper
>
> instead of
>
> lower < x & x < upper
>
>
>
> On Mon, Mar 18, 2013 at 10:16 AM, S Ellison <S.Ellison at lgcgroup.com> wrote:
>
>>>> 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 u...{{dropped:19}}
>
> ______________________________________________
> 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.