Re: [R] Sample

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 26 Jul 2008 17:21:41 -0400

like this:

> x

  0-100 100-250 250+

a     9      18   16
b    33      25   27
c    21      19   17
d    25      22   19
e    40      39   19
f    77      45   29

> x[sample(nrow(x), 3),]

  0-100 100-250 250+
e    40      39   19
c    21      19   17
a     9      18   16

> x[sample(nrow(x), 3),]

  0-100 100-250 250+
c    21      19   17
e    40      39   19
d    25      22   19

> x[sample(nrow(x), 3),]

  0-100 100-250 250+
b    33      25   27
f    77      45   29
c    21      19   17

> x[sample(nrow(x), 3),]

  0-100 100-250 250+
f    77      45   29
c    21      19   17
a     9      18   16


On Sat, Jul 26, 2008 at 5:12 PM, Raphael Saldanha <saldanha.plangeo_at_gmail.com> wrote:
> Hi!
>
> I have a data.frame, like this one:
>
>> data
> 0-100 100-250 250+
> a 9 18 16
> b 33 25 27
> c 21 19 17
> d 25 22 19
> e 40 39 19
> f 77 45 29
>
> If I request a sample of 2, I have the following:
>
>> sample(data, 2)
> 0-100 250+
> a 9 16
> b 33 27
> c 21 17
> d 25 19
> e 40 19
> f 77 29
>
> How can I request a sample from the rows???
>
>
> --
> Raphael Saldanha
> UFJF - Brazil
> saldanha.plangeo_at_gmail.com
>
>
> Woody Allen - "I don't want to achieve immortality through my work. I want
> to achieve it through not dying."
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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 Sat 26 Jul 2008 - 21:33:23 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 Sat 26 Jul 2008 - 22:32:58 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