Re: [R] Randomly remove condition-selected rows from a matrix

2009-01-02 Thread Wacek Kusnierczyk
Stavros Macrakis wrote: On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron carnivorescie...@gmail.com wrote: m[-sample(which(m[,1]8 m[,2]12),2),] Supposing I sample only one row among the ones matching my criteria. Then consider the case where there is just one row matching this

Re: [R] Randomly remove condition-selected rows from a matrix

2009-01-02 Thread Duncan Murdoch
On 02/01/2009 10:07 AM, Wacek Kusnierczyk wrote: Stavros Macrakis wrote: On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron carnivorescie...@gmail.com wrote: m[-sample(which(m[,1]8 m[,2]12),2),] Supposing I sample only one row among the ones matching my criteria. Then consider the

Re: [R] Randomly remove condition-selected rows from a matrix

2009-01-02 Thread Wacek Kusnierczyk
xxx wrote: On Fri, Jan 2, 2009 at 10:07 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: ... 'sample' takes a sample of the specified size from the elements of 'x' using either with or without replacement. x: Either a (numeric, complex, character or

Re: [R] Randomly remove condition-selected rows from a matrix

2009-01-02 Thread Stavros Macrakis
There is another undocumented glitch in sample: sample(2^31-1,1) = OK sample(2^31 ,1) = Error I suppose you could interpret sampling takes place from '1:x' to mean that 1:x is actually generated, but that doesn't work as an explanation either; on my 32-bit Windows box, 1:(2^29) gives

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-31 Thread Guillaume Chapron
I believe this does what you want: m[-sample(which(m[,1]8 m[,2]12),2),] Analysis: Get a boolean vector of rows fitting criteria: m[,1]8 m[,2]12 What are their indexes? which(...) Choose two among those indexes: sample(...,2) Thanks, but this does not seem to always work.

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-31 Thread Charles C. Berry
On Wed, 31 Dec 2008, Guillaume Chapron wrote: I believe this does what you want: m[-sample(which(m[,1]8 m[,2]12),2),] Analysis: Get a boolean vector of rows fitting criteria: m[,1]8 m[,2]12 What are their indexes? which(...) Choose two among those indexes: sample(...,2)

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-31 Thread Stavros Macrakis
On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron carnivorescie...@gmail.com wrote: m[-sample(which(m[,1]8 m[,2]12),2),] Supposing I sample only one row among the ones matching my criteria. Then consider the case where there is just one row matching this criteria. Sure, there is no need to

[R] Randomly remove condition-selected rows from a matrix

2008-12-30 Thread Guillaume Chapron
Hello all, I create the following matrix: m - matrix(1:20, nrow = 10, ncol = 2) which looks like: [,1] [,2] [1,]1 11 [2,]2 12 [3,]3 13 [4,]4 14 [5,]5 15 [6,]6 16 [7,]7 17 [8,]8 18 [9,]9 19 [10,] 10 20 Then, I want to

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-30 Thread Sarah Goslee
Assuming your values aren't always in such neat order, you could use something like: valtoremove1 - sample((1:nrow(m))[m[,1] 8], 1) valtoremove2 - sample((1:nrow(m))[m[,1] 12], 1) Sarah On Tue, Dec 30, 2008 at 9:59 AM, Guillaume Chapron carnivorescie...@gmail.com wrote: Hello all, I create

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-30 Thread Daniel Malter
Hi, The approach below uses a function. The nice thing about it is that you can define the cutoff values dynamically (i.e. what is 8 and 12 in your example). The functions extract a row index to remove. Be aware that there is no warning if both return the same row index. You might have to adjust

Re: [R] Randomly remove condition-selected rows from a matrix

2008-12-30 Thread Stavros Macrakis
I believe this does what you want: m[-sample(which(m[,1]8 m[,2]12),2),] Analysis: Get a boolean vector of rows fitting criteria: m[,1]8 m[,2]12 What are their indexes? which(...) Choose two among those indexes: sample(...,2) Choose all except the selected rows from the