Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Thanks a lot. That solves the problem :) best, salih On Sat, Jun 25, 2011 at 9:13 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: yet another solution is: v - c(1, 2, 6, 5) w - matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) check - outer(w[, 1], v, -) * outer(w[, 2], v, -) v[which(check = 0, arr.ind = TRUE)[, 2]] Best, Dimitris On 6/24/2011 10:05 PM, Martin Morgan wrote: On 06/24/2011 11:12 AM, Dennis Murphy wrote: Hi: Not much different from Peter's approach, but here's another try: v- c(1, 2, 6, 5) w- matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) w [,1] [,2] [1,] 1 4 [2,] 3 5 [3,] 8 10 f- function(x) v[which(v= x[1] v= x[2])] unlist(apply(w, 1, f)) [1] 1 2 5 If you just do the apply() part, the function will return a list of those elements of v that fall within the i-th interval. Maybe v = c(1, 2, 6, 5) start = c(-Inf, 1, 3, 8) end = c(-Inf, 4, 5, 10) v[ v = end[findInterval(v, start)] ] Also IRanges::findOverlaps / countOverlaps in Bioconductor v[countOverlaps(IRanges(v, v), IRanges(start, end)) != 0] http://bioconductor.org/**install http://bioconductor.org/install Martin HTH, Dennis On Fri, Jun 24, 2011 at 9:52 AM, Salih Tunasaliht...@gmail.com wrote: Hi guys, let's assume i have the following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphydjmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tunasaliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x- rnorm(5) y- matrix(rnorm(5*2), 5, 2) check- y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**http://www.r-project.org/** posting-guide.htmlhttp://www.**r-project.org/posting-guide.**htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/http://www.erasmusmc.nl/**biostatistiek/ http://www.**erasmusmc.nl/biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://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-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
try sqldf: require(sqldf) x x 1 1 2 2 3 6 4 5 y s e 1 1 4 2 3 5 3 8 10 sqldf( + select x.x + from x, y + where x.x between y.s and y.e + ) x 1 1 2 2 3 5 On Mon, Jun 27, 2011 at 5:33 AM, Salih Tuna saliht...@gmail.com wrote: Thanks a lot. That solves the problem :) best, salih On Sat, Jun 25, 2011 at 9:13 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: yet another solution is: v - c(1, 2, 6, 5) w - matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) check - outer(w[, 1], v, -) * outer(w[, 2], v, -) v[which(check = 0, arr.ind = TRUE)[, 2]] Best, Dimitris On 6/24/2011 10:05 PM, Martin Morgan wrote: On 06/24/2011 11:12 AM, Dennis Murphy wrote: Hi: Not much different from Peter's approach, but here's another try: v- c(1, 2, 6, 5) w- matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) w [,1] [,2] [1,] 1 4 [2,] 3 5 [3,] 8 10 f- function(x) v[which(v= x[1] v= x[2])] unlist(apply(w, 1, f)) [1] 1 2 5 If you just do the apply() part, the function will return a list of those elements of v that fall within the i-th interval. Maybe v = c(1, 2, 6, 5) start = c(-Inf, 1, 3, 8) end = c(-Inf, 4, 5, 10) v[ v = end[findInterval(v, start)] ] Also IRanges::findOverlaps / countOverlaps in Bioconductor v[countOverlaps(IRanges(v, v), IRanges(start, end)) != 0] http://bioconductor.org/**install http://bioconductor.org/install Martin HTH, Dennis On Fri, Jun 24, 2011 at 9:52 AM, Salih Tunasaliht...@gmail.com wrote: Hi guys, let's assume i have the following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphydjmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tunasaliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x- rnorm(5) y- matrix(rnorm(5*2), 5, 2) check- y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**http://www.r-project.org/** posting-guide.htmlhttp://www.**r-project.org/posting-guide.**htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/http://www.erasmusmc.nl/**biostatistiek/ http://www.**erasmusmc.nl/biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://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-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
yet another solution is: v - c(1, 2, 6, 5) w - matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) check - outer(w[, 1], v, -) * outer(w[, 2], v, -) v[which(check = 0, arr.ind = TRUE)[, 2]] Best, Dimitris On 6/24/2011 10:05 PM, Martin Morgan wrote: On 06/24/2011 11:12 AM, Dennis Murphy wrote: Hi: Not much different from Peter's approach, but here's another try: v- c(1, 2, 6, 5) w- matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) w [,1] [,2] [1,] 1 4 [2,] 3 5 [3,] 8 10 f- function(x) v[which(v= x[1] v= x[2])] unlist(apply(w, 1, f)) [1] 1 2 5 If you just do the apply() part, the function will return a list of those elements of v that fall within the i-th interval. Maybe v = c(1, 2, 6, 5) start = c(-Inf, 1, 3, 8) end = c(-Inf, 4, 5, 10) v[ v = end[findInterval(v, start)] ] Also IRanges::findOverlaps / countOverlaps in Bioconductor v[countOverlaps(IRanges(v, v), IRanges(start, end)) != 0] http://bioconductor.org/install Martin HTH, Dennis On Fri, Jun 24, 2011 at 9:52 AM, Salih Tunasaliht...@gmail.com wrote: Hi guys, let's assume i have the following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphydjmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tunasaliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x- rnorm(5) y- matrix(rnorm(5*2), 5, 2) check- y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih Can you explain what is probe and what is region and how Dimitri's code failed to do what you wanted? Only if x is between y values you get one number in check negative and one positive and their multiplication is therefore lower than zero. Regards Petr On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/ mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/ biostatistiek/ [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tuna saliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi guys, let's assume i havethe following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tuna saliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**http://www.r-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/ http://www.erasmusmc.nl/biostatistiek/ [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
On 2011-06-24 09:52, Salih Tuna wrote: Hi guys, let's assume i havethe following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. Probably not faster, but try: x - c(1,2,6,5) y - matrix( c(1,3,8,4,5,10), 3, 2 ) ok - vector( 'logical', length(x) ) for( i in seq_along(x) ) ok[i] - any( apply(y - x[i], 1, prod) = 0 ) x[ok] Peter Ehlers best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphydjmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tunasaliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x- rnorm(5) y- matrix(rnorm(5*2), 5, 2) check- y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**http://www.r-project.org/** posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/ http://www.erasmusmc.nl/biostatistiek/ [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
Hi: Not much different from Peter's approach, but here's another try: v - c(1, 2, 6, 5) w - matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) w [,1] [,2] [1,]14 [2,]35 [3,]8 10 f - function(x) v[which(v = x[1] v = x[2])] unlist(apply(w, 1, f)) [1] 1 2 5 If you just do the apply() part, the function will return a list of those elements of v that fall within the i-th interval. HTH, Dennis On Fri, Jun 24, 2011 at 9:52 AM, Salih Tuna saliht...@gmail.com wrote: Hi guys, let's assume i have the following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tuna saliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x - rnorm(5) y - matrix(rnorm(5*2), 5, 2) check - y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[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.
Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y
On 06/24/2011 11:12 AM, Dennis Murphy wrote: Hi: Not much different from Peter's approach, but here's another try: v- c(1, 2, 6, 5) w- matrix(c(1, 4, 3, 5, 8, 10), ncol = 2, byrow = TRUE) w [,1] [,2] [1,]14 [2,]35 [3,]8 10 f- function(x) v[which(v= x[1] v= x[2])] unlist(apply(w, 1, f)) [1] 1 2 5 If you just do the apply() part, the function will return a list of those elements of v that fall within the i-th interval. Maybe v = c(1, 2, 6, 5) start = c(-Inf, 1, 3, 8) end = c(-Inf, 4, 5, 10) v[ v = end[findInterval(v, start)] ] Also IRanges::findOverlaps / countOverlaps in Bioconductor v[countOverlaps(IRanges(v, v), IRanges(start, end)) != 0] http://bioconductor.org/install Martin HTH, Dennis On Fri, Jun 24, 2011 at 9:52 AM, Salih Tunasaliht...@gmail.com wrote: Hi guys, let's assume i havethe following 1 x = 2 6 5 1 4 y = 3 5 8 10 i want the code to report back 1, 2 and 5 from x. Basically it shopuld check whether each elements of x falls in the range of each row of x. 1 and 2 falls in between 1-4 and 5 falls in between 3-5. I do this with two for loops but in the case of very large list, it takes ages. best, salih On Fri, Jun 24, 2011 at 4:12 PM, Dennis Murphydjmu...@gmail.com wrote: Hi: That leaves open several possibilities. Could you please supply a small, reproducible example (i.e., one that someone can copy and paste into an R session) that illustrates the problem along with the solution you expect? TIA, Dennis On Fri, Jun 24, 2011 at 2:30 AM, Salih Tunasaliht...@gmail.com wrote: Hi Dimitris, Thanks for your reply. But this is not exactly what i am after. I want to find the probes that falls into certain regions. In your solution it will ignore the second probe if it falls into the same region as the first one. Is there any vector trickb uilt in R to find whether probes fall into certain regions? best, salih On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: One approach is the following: x- rnorm(5) y- matrix(rnorm(5*2), 5, 2) check- y - x check[, 1] * check[, 2] 0 I hope it helps. Best, Dimitris On 6/24/2011 10:57 AM, Salih Tuna wrote: Hi All, What is the fastest way of finding if any members of vector x fall in the range of the rows of matrix y? I do not want to use two for loops as this will take forever. Any help will be appreciated, best, salih [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/ [[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. -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ 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.