[R] Removing values from a vector

Joseph Sakshaug sakshaug at u.washington.edu
Fri Apr 16 03:51:01 CEST 2004


Dear R-help faithful,

I am trying to build a program which will take repeated samples (w/o
replacement) from a population of values. The interesting catch is that I
would like the sample values to be removed from the population, after each
sample is taken.

For example:

pop<-1:10

sample(pop, 2) = lets say, (3, 7)

## This is where I would like values (3, 7) to be removed from the
population vector, giving a new "current" population vector:

"new" pop = [1, 2, 4, 5, 6, 8, 9, 10]
and has length 8 instead of 10.


At first I tried to run a loop and comparison of (sample.pop == pop) and
IF a FALSE was found the loop would store the [ith] value of sample.pop
in a new vector called pop.current. Then, due to my beginning programming
skills, I kind of got stuck linking pop.current to the population which is
to be sampled from...


I know that in PHP there is a function called unset() which removes values
from an array. Does R have an equivalent function?

Thanks in advance.

Joe




More information about the R-help mailing list