Thats cumbersome, Arun.

> sum(mat1[,1] < 12 & mat1[,2] > 12)
[1] 17

will do the job and even faster:

> system.time(replicate(10000, sum(mat1[,1] < 12 & mat1[,2] > 12)))
#   user  system elapsed
#  0.067   0.001   0.078

HTH,
Jorge.-


On Tue, Mar 19, 2013 at 1:06 AM, arun <> wrote:

> 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 <>
> To: r-help@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@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.
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

