choose randomly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

choose randomly

Medic
Variable temperature:
mydata$temperature
has N values.
With what code to сhoice (without return) n values from them RANDOMLY?

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: choose randomly

Jim Lemon-4
Hi Medic,
mydata$Temperature[sample(1:N,N)
should do the trick. You will just get a pseudo-randomly shuffled set
of the same values.

Jim

On Thu, Dec 19, 2019 at 7:34 AM Medic <[hidden email]> wrote:

>
> Variable temperature:
> mydata$temperature
> has N values.
> With what code to сhoice (without return) n values from them RANDOMLY?
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: choose randomly

Bert Gunter-2
If n = N, then this is unnecessarily complicated.

sample(mydata$Temperature)

is all you need (see ?sample).

If n < N, then the "trick" is not done.

sample(mydata$Temperature, n)

is what is wanted.

Bert



On Wed, Dec 18, 2019 at 12:54 PM Jim Lemon <[hidden email]> wrote:

> Hi Medic,
> mydata$Temperature[sample(1:N,N)
> should do the trick. You will just get a pseudo-randomly shuffled set
> of the same values.
>
> Jim
>
> On Thu, Dec 19, 2019 at 7:34 AM Medic <[hidden email]> wrote:
> >
> > Variable temperature:
> > mydata$temperature
> > has N values.
> > With what code to сhoice (without return) n values from them RANDOMLY?
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.