Skip to content
Prev 78645 / 398502 Next

How to get the remaining vector after sampling a subset?

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