Re: [R] sampling from a list of values while excluding one

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 21 Jul 2008 05:43:25 -0400

Here is one way of doing it by removing the element from the vector

> # exclude the 3rd element of the vector
> sample((1:10)[-3], 10, TRUE)

 [1] 4 5 7 10 2 10 10 7 7 1
>

On Mon, Jul 21, 2008 at 5:10 AM, Juliane Struve <juliane_struve_at_yahoo.co.uk> wrote:
> Dear list,
>
>
> I am trying to sample from a list of integers 1:10, but need to exclude one of them. The one to be excluded is a variable called "number" and can take values 1:10. The line below does not work, but shows what I am trying to do. Would somebody be able to help me with the syntax ?
>
> anglenumber=sample(1:10, exclude = "number",size=1,replace=TRUE)
>
> Thank you very much for a hint.
>
> Regards,
>
> Juliane
>
>
> Dr. Juliane Struve
> Environmental Scientist
> 10, Lynwood Crescent
> Sunningdale SL5 0BL
> 01344 620811
>
>
> __________________________________________________________
> Not happy with your email address?.
> Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html
>
> ______________________________________________
> R-help_at_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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_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.
Received on Mon 21 Jul 2008 - 09:47:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Jul 2008 - 10:32:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive