[R] exclude a vector value from another vector

2008-12-01 Thread Hamid Hamid
Dear All,
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<-c(1,5,14,7,9,12,18,19,65,54)


sample(pop, 2) = lets say, (5,54)
## This is where I would like values (5, 54) to be removed from the
population vector, giving a new "current" population vector:


"new" pop = [1,14,7,9,12,18,19,65]
and has length 8 instead of 10.

In the cases when the size of pop and deriven sample of it is enough large
using the following command is not helpful.
newpop<-pop[-c(2,10)]

One could simplify my question in this way: how we can exclude a sub vector
values from a super  vector value (i.e sub vecor values are subset of super
vector values).
Thanks in advance.
Hamid

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] exclude a vector value from another vector

2008-12-01 Thread Jorge Ivan Velez
Dear Hamid,
Try this:

> pop<-c(1,5,14,7,9,12,18,19,65,54)
> pop
 [1]  1  5 14  7  9 12 18 19 65 54
> spop<-sample(pop,2)
> spop
[1] 14 19
> newpop=pop[!pop%in%spop]
> newpop
[1]  1  5  7  9 12 18 65 54

See ?"%in%"" for more information.

HTH,

Jorge



On Mon, Dec 1, 2008 at 2:16 PM, Hamid Hamid <[EMAIL PROTECTED]> wrote:

> Dear All,
> 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<-c(1,5,14,7,9,12,18,19,65,54)
>
>
> sample(pop, 2) = lets say, (5,54)
> ## This is where I would like values (5, 54) to be removed from the
> population vector, giving a new "current" population vector:
>
>
> "new" pop = [1,14,7,9,12,18,19,65]
> and has length 8 instead of 10.
>
> In the cases when the size of pop and deriven sample of it is enough large
> using the following command is not helpful.
> newpop<-pop[-c(2,10)]
>
> One could simplify my question in this way: how we can exclude a sub vector
> values from a super  vector value (i.e sub vecor values are subset of super
> vector values).
> Thanks in advance.
> Hamid
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] exclude a vector value from another vector

2008-12-02 Thread Greg Snow
Others have shown ways to remove your sample from the population, but this may 
be doing things the long way.  If you just want several samples from the same 
population without overlap between any of the samples, just take one sample of 
size equal to the sum of the individual sample sizes, randomize the order, then 
split it into the individual samples.

For example, to get 6 samples of size 4 from the population of "LETTERS":

> mysamples <- matrix( sample(LETTERS, 24), ncol=6 )
> mysamples
 [,1] [,2] [,3] [,4] [,5] [,6]
[1,] "F"  "L"  "H"  "A"  "S"  "P"
[2,] "M"  "D"  "U"  "N"  "G"  "C"
[3,] "O"  "R"  "E"  "V"  "K"  "W"
[4,] "J"  "X"  "B"  "T"  "Z"  "I"
>

Now each column is a sample, us apply or a for loop to work on each one.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> project.org] On Behalf Of Hamid Hamid
> Sent: Monday, December 01, 2008 12:17 PM
> To: r-help@r-project.org
> Subject: [R] exclude a vector value from another vector
>
> Dear All,
> 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<-c(1,5,14,7,9,12,18,19,65,54)
>
>
> sample(pop, 2) = lets say, (5,54)
> ## This is where I would like values (5, 54) to be removed from the
> population vector, giving a new "current" population vector:
>
>
> "new" pop = [1,14,7,9,12,18,19,65]
> and has length 8 instead of 10.
>
> In the cases when the size of pop and deriven sample of it is enough
> large
> using the following command is not helpful.
> newpop<-pop[-c(2,10)]
>
> One could simplify my question in this way: how we can exclude a sub
> vector
> values from a super  vector value (i.e sub vecor values are subset of
> super
> vector values).
> Thanks in advance.
> Hamid
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] exclude a vector value from another vector

2008-12-02 Thread Henrique Dallazuanna
Try this:

setdiff(pop, sample(pop, 2))


On Mon, Dec 1, 2008 at 5:16 PM, Hamid Hamid <[EMAIL PROTECTED]> wrote:

> Dear All,
> 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<-c(1,5,14,7,9,12,18,19,65,54)
>
>
> sample(pop, 2) = lets say, (5,54)
> ## This is where I would like values (5, 54) to be removed from the
> population vector, giving a new "current" population vector:
>
>
> "new" pop = [1,14,7,9,12,18,19,65]
> and has length 8 instead of 10.
>
> In the cases when the size of pop and deriven sample of it is enough large
> using the following command is not helpful.
> newpop<-pop[-c(2,10)]
>
> One could simplify my question in this way: how we can exclude a sub vector
> values from a super  vector value (i.e sub vecor values are subset of super
> vector values).
> Thanks in advance.
> Hamid
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.