Re: [R] Selecting values based on two criteria

2014-12-26 Thread Boris Steipe
Try this: d1 <- c(135631,136950,137952,138787,139623,142231,143067,144762, 145601,146441) d2 <- c(135882,136954,137956,138792,139630,140569,141398,142237, 143078,143907,144771,145611,146446,147285,148128) len <- length(d1) # concatenate the two vectors mrg <- c(d1,d2) # order the

[R] Selecting values based on two criteria

2014-12-26 Thread Morway, Eric
I'm in need of help selecting from d2 those values that come after a value in d1. For example, d2[1] is both greater than d1[1] and is the value that is closest to d2[1]. Similarly, d2[2] is both greater than d1[2] and is the next "highest" number in d2. Every value in d1 has a corresponding val

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Prof Brian Ripley
On Wed, 25 Jun 2008, Gabor Csardi wrote: Wow, that is smart, although is seems to be overkill. I guess 'duplicated' is better than O(n^2), is it really? Yes as it hashes, but the overhead on short vectors is high since it always hashes. Gabor On Wed, Jun 25, 2008 at 05:43:30PM +0100,

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Gabor Csardi
Wow, that is smart, although is seems to be overkill. I guess 'duplicated' is better than O(n^2), is it really? Gabor On Wed, Jun 25, 2008 at 05:43:30PM +0100, Prof Brian Ripley wrote: > On Wed, 25 Jun 2008, Marc Schwartz wrote: > >> on 06/25/2008 11:19 AM Daren Tan wrote: >>> >>> unique(c(1

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Gabor Grothendieck
On Wed, Jun 25, 2008 at 12:19 PM, Daren Tan <[EMAIL PROTECTED]> wrote: > > > unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get > only 2:10 (i.e. values that are unique) ? > > Try this: setdiff(x, x[duplicated(x)]) __ R-help

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Marc Schwartz
on 06/25/2008 11:44 AM Gabor Csardi wrote: I'm sorry to say, but this one is wrong, too. Maybe coffee really helps, I just had one. :) Vec <- c(20:30,20) which(table(Vec) == 1) 21 22 23 24 25 26 27 28 29 30 2 3 4 5 6 7 8 9 10 11 You would actually need the names, but that would invo

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Gabor Csardi
I'm sorry to say, but this one is wrong, too. Maybe coffee really helps, I just had one. :) > Vec <- c(20:30,20) > which(table(Vec) == 1) 21 22 23 24 25 26 27 28 29 30 2 3 4 5 6 7 8 9 10 11 You would actually need the names, but that would involve some numberic -> character -> numeric

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Prof Brian Ripley
On Wed, 25 Jun 2008, Marc Schwartz wrote: on 06/25/2008 11:19 AM Daren Tan wrote: unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? The easiest might be: Vec [1] 1 2 3 4 5 6 7 8 9 10 1 Vec[table(Vec) == 1]

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Gabor Csardi
Hmmm, this is not very good: > Vec <- c(10:1,1) > Vec[ table(Vec) == 1 ] [1] 9 8 7 6 5 4 3 2 1 and these are obviously not the unique values. This one is better: Vec [ ! duplicated(Vec) & ! duplicated(Vec, fromLast=TRUE) ] Gabor On Wed, Jun 25, 2008 at 11:29:31AM -0500, Marc Schwartz wrote

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Marc Schwartz
on 06/25/2008 11:29 AM Marc Schwartz wrote: on 06/25/2008 11:19 AM Daren Tan wrote: unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? The easiest might be: > Vec [1] 1 2 3 4 5 6 7 8 9 10 1 > Vec[table(Vec) =

Re: [R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Marc Schwartz
on 06/25/2008 11:19 AM Daren Tan wrote: unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? The easiest might be: > Vec [1] 1 2 3 4 5 6 7 8 9 10 1 > Vec[table(Vec) == 1] [1] 2 3 4 5 6 7 8 9 10 HTH, Marc

[R] selecting values that are unique, instead of selecting unique values

2008-06-25 Thread Daren Tan
unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any method to get only 2:10 (i.e. values that are unique) ? _ Easily edit your photos like a pro with Photo Gallery. [[alternative HTML version deleted]] _

Re: [R] Selecting values

2007-09-28 Thread Marc Schwartz
Here is yet another approach using aggregate(), which internally, basically does what my first solution did: > aggregate(z[, 2], list(z[, 1]), "[", 1) Group.1 x 1 1 -1.2006469 2 2 -0.1614918 3 3 -0.5717729 4 4 -0.2398887 5 5 1.1690564 See ?aggregate Note

Re: [R] Selecting values

2007-09-28 Thread Matthew Keller
Is this easier? x.index <- duplicated(x.sample)==FALSE cbind(x.sample[x.index],y[x.index]) - Matt On 9/28/07, Marc Schwartz <[EMAIL PROTECTED]> wrote: > On Fri, 2007-09-28 at 17:48 -0400, Brian Perron wrote: > > Hello all, > > > > An elementary question that I am sure can be easily cracked by a

Re: [R] Selecting values

2007-09-28 Thread Marc Schwartz
On Fri, 2007-09-28 at 17:48 -0400, Brian Perron wrote: > Hello all, > > An elementary question that I am sure can be easily cracked by an R > enthusiast. Let's say I have multiple scores (y) on subjects (x.sample). > Some subjects have a few more scores than others. Can somebody suggest some > c

[R] Selecting values

2007-09-28 Thread Brian Perron
Hello all, An elementary question that I am sure can be easily cracked by an R enthusiast. Let's say I have multiple scores (y) on subjects (x.sample). Some subjects have a few more scores than others. Can somebody suggest some code that will select the first score for each subject? For example