[R] Row Sampling

jim holtman jholtman at gmail.com
Mon Oct 20 18:00:25 CEST 2008


Is this what you want:

> x <- read.table(textConnection(" s1 s2 s3 s4
+ 1   0  0  0  1
+ 2   1  0  1  0
+ 3   0  0  0  0
+ 4   0  0  0  0
+ 5   0  1  0  1
+ 6   1  0  0  0
+ 7   0  0  0  0
+ 8   0  0  0  0
+ 9   0  0  0  0
+ 10  0  0  0  1"), header=TRUE)
> closeAllConnections()
> for (i in 1:5){  # take 5 samples
+     print(x[sample(nrow(x), 5),])
+ }
   s1 s2 s3 s4
7   0  0  0  0
4   0  0  0  0
3   0  0  0  0
10  0  0  0  1
9   0  0  0  0
  s1 s2 s3 s4
3  0  0  0  0
2  1  0  1  0
4  0  0  0  0
7  0  0  0  0
8  0  0  0  0
   s1 s2 s3 s4
10  0  0  0  1
7   0  0  0  0
3   0  0  0  0
4   0  0  0  0
1   0  0  0  1
   s1 s2 s3 s4
1   0  0  0  1
7   0  0  0  0
10  0  0  0  1
4   0  0  0  0
9   0  0  0  0
   s1 s2 s3 s4
10  0  0  0  1
5   0  1  0  1
4   0  0  0  0
2   1  0  1  0
9   0  0  0  0


On Mon, Oct 20, 2008 at 10:00 AM, Alex99 <loyola9988 at yahoo.com> wrote:
>
>
> Hi everyone,
> does any one knows how can I make sample from rows?
> i.e. I have a data like this:
>
>  s1 s2 s3 s4
> 1   0  0  0  1
> 2   1  0  1  0
> 3   0  0  0  0
> 4   0  0  0  0
> 5   0  1  0  1
> 6   1  0  0  0
> 7   0  0  0  0
> 8   0  0  0  0
> 9   0  0  0  0
> 10  0  0  0  1
>
> I need to make 5 different sample with 5 different persons(rows) in each
> sample from it keeping s1,s3,s3,s4 but changing rows. I cant get "replicate"
> or "sample" functions to make samples by changing the rows.
>
> Thanks
>
> --
> View this message in context: http://www.nabble.com/Row-Sampling-tp20067830p20067830.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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 that you are trying to solve?



More information about the R-help mailing list