Re: [R] how to get values within a threshold

2013-09-13 Thread Zhang Weiwu
On Fri, 13 Sep 2013, William Dunlap wrote: You may want to append -Inf (or 0 if you know the data cannot be negative) to the start of your 'values' vector so you don't have to write code to catch the cases when a threshold is below the range of the values. > findInterval(thresholds, c(0,valu

Re: [R] how to get values within a threshold

2013-09-13 Thread William Dunlap
tpink...@yahoo.com > Cc: r-help@r-project.org > Subject: RE: [R] how to get values within a threshold > > > > On Fri, 13 Sep 2013, William Dunlap wrote: > > >> findInterval(thresholds, values) > > [1] 1 4 4 4 7 > > Thanks a lot! But now I have a new probl

Re: [R] how to get values within a threshold

2013-09-13 Thread Zhang Weiwu
On Fri, 13 Sep 2013, William Dunlap wrote: findInterval(thresholds, values) [1] 1 4 4 4 7 Thanks a lot! But now I have a new problem, a typical R issue perhaps. First, let's look at a successful case: > thresholds <- c(1,3,5,7,9) > values <- c(0.854, 1.648, 1.829, 1.874,

Re: [R] how to get values within a threshold

2013-09-13 Thread arun
f Zhang Weiwu > Sent: Friday, September 13, 2013 3:14 AM > To: r-help@r-project.org > Subject: [R] how to get values within a threshold > > > input: > >      > values >      [1] 0.854400 1.648465 1.829830 1.874704 7.670915 7.673585 7.722619 > >      > thresho

Re: [R] how to get values within a threshold

2013-09-13 Thread William Dunlap
AM > To: r-help@r-project.org > Subject: [R] how to get values within a threshold > > > input: > > > values > [1] 0.854400 1.648465 1.829830 1.874704 7.670915 7.673585 7.722619 > > > thresholds > [1] 1 3 5 7 9 > > expected

Re: [R] how to get values within a threshold

2013-09-13 Thread arun
on(x) {sum(val1 To: Zhang Weiwu Cc: R help Sent: Friday, September 13, 2013 9:27 AM Subject: Re: [R] how to get values within a threshold Hi, You could try: val1<- c(0.854400, 1.648465, 1.829830, 1.874704, 7.670915, 7.673585, 7.722619) thresh1<- c(1,3,5,7,9) rowSums(t(replicate(length(thre

Re: [R] how to get values within a threshold

2013-09-13 Thread arun
Cc: Sent: Friday, September 13, 2013 6:13 AM Subject: [R] how to get values within a threshold input:     > values     [1] 0.854400 1.648465 1.829830 1.874704 7.670915 7.673585 7.722619     > thresholds     [1] 1 3 5 7 9 expected output:     [1] 1 4 4 4 7 That is, need a vector of

[R] how to get values within a threshold

2013-09-13 Thread Zhang Weiwu
input: > values [1] 0.854400 1.648465 1.829830 1.874704 7.670915 7.673585 7.722619 > thresholds [1] 1 3 5 7 9 expected output: [1] 1 4 4 4 7 That is, need a vector of indexes of the maximum value below the threshold. e.g. First element is "1", becaus