Skip to content
Back to formatted view

Raw Message

Message-ID: <4348E5DA.1040103@pdf.com>
Date: 2005-10-09T09:41:46Z
From: Sundar Dorai-Raj
Subject: How to get the remaining vector after sampling a subset?
In-Reply-To: <cedaa40b0510090226x3d2d3242ua12d5dc1431203eb@mail.gmail.com>

Xiao Shi wrote:
> Hi ,
> I have a vector,for example,
> x=rnorm(100)
> Then i rendom choose 20 of them.
> chosen=sample(x,20).
> And i want to get the remain values in x.
> Is there a quick way to go?
> 
> Thanks in advance.
> 
> 	[[alternative HTML version deleted]]
> 

How about:

x <- rnorm(100)
y <- sample(x, 20)
z <- x[!x %in% y]

But probably a safer way is to sample the indicies:

x <- rnorm(100)
w <- sample(length(x), 20)
y <- x[w]
z <- x[-w]

HTH,

--sundar