[R] choosing a random sample by precentage

Joshua Wiley jwiley.psych at gmail.com
Fri Jul 23 00:57:00 CEST 2010


Hi Ethan,

Sure with a bit of extra work:

x <- matrix(1:109, ncol = 1)
x[sample(nrow(x), trunc(nrow(x)*.1)), ]

you could also use round() in place of trunc(), you just need
something to get it to an integer.  If you didn't like having to type
the name several times you could make a simple function to do it for
you.

HTH,

Josh

On Thu, Jul 22, 2010 at 3:49 PM, Xebar Saram <zeltakc at gmail.com> wrote:
> hi all
>
> i have found the follwoing way to choose a random sample by sample size (200):
>
> ten_per_T2000 <- F_T2000_All[sample(nrow(F_T2000_All), 200), ]
>
>
>  but i wondered if there is a way to choose a sample size by
> precentage (10% etc..)
>
> thx
>
> ethan
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list