Skip to content

How to get the remaining vector after sampling a subset?

3 messages · Xiao Shi, Sundar Dorai-Raj, Dimitris Rizopoulos

#
Xiao Shi wrote:
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
#
one way is to use:

x[!x %in% chosen]


I hope it helps.

Best,
Dimitris


----- Original Message ----- 
From: "Xiao Shi" <bioconductor.cn at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Sunday, October 09, 2005 11:26 AM
Subject: [R] How to get the remaining vector after sampling a subset?
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm