[R] Counting confidence intervals

arun smartpink111 at yahoo.com
Mon Mar 18 15:06:38 CET 2013


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

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.



More information about the R-help mailing list