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) giv
xxx wrote:
> On Fri, Jan 2, 2009 at 10:07 AM, Wacek Kusnierczyk
> 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 logical) vector of
>> mo
On 02/01/2009 10:07 AM, Wacek Kusnierczyk wrote:
Stavros Macrakis wrote:
On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron
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 jus
Stavros Macrakis wrote:
> On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron
> 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.
On Wed, Dec 31, 2008 at 12:44 PM, Guillaume Chapron
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 sample, but the ins
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)
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.
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 or
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
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
wrote:
> Hello all,
>
> I create the following matri
10 matches
Mail list logo