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
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/
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Xebar Saram > Sent: Thursday, July 22, 2010 3:50 PM > To: r-help at r-project.org > Subject: [R] choosing a random sample by precentage > > 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 >Maybe something like:>ten_per_T2000 <- F_T2000_All[sample(nrow(F_T2000_All), 0.1*nrow(F_T2000_All)), ]Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
Hi Joshua: how to do a permutation test on the following sample with the sample size in 20000 : id weight P VALUE 100 100 101 200 102 200 103 150 ....... Thanks -- View this message in context: http://r.789695.n4.nabble.com/choosing-a-random-sample-by-precentage-tp2299509p2299529.html Sent from the R help mailing list archive at Nabble.com.
On Thu, Jul 22, 2010 at 4:11 PM, jd6688 <jdsignature at gmail.com> wrote:> > Hi Joshua: > > how to do a permutation test on the following sample with the sample size in > 20000 :Take a look at some of the results from RSiteSearch("permutation test") the "coin" package also comes to mind Josh> > id ? ? ? ?weight ? ? ?P VALUE > > 100 ? ? ?100 > 101 ? ? ? 200 > 102 ? ? ? 200 > 103 ? ? ? 150 > > > ....... > > Thanks > -- > View this message in context: http://r.789695.n4.nabble.com/choosing-a-random-sample-by-precentage-tp2299509p2299529.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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
Hi Ethan, I should clarify that you do not *need* to make size an integer, so you technically do not need trunc(), but if you use trunc() or round(), you get to be in control of what you get. To answer your second question, look at this little function, it even lets you choose different percentages. Notice how using -random.rows, one is able to select all BUT those rows. Cheers, Josh #Data for the example x <- matrix(1:40, ncol = 2) my.sampler <- function(name, percentage = 10){ random.rows <- sample(nrow(name), trunc(nrow(x)*(percentage/100))) x.1 <- name[random.rows, ] x.2 <- name[-random.rows, ] value <- list(x.random = x.1, x.allelse = x.2) return(value) } #So you can see my.sampler(x) output <- my.sampler(x) output$x.random output$x.allelse On Thu, Jul 22, 2010 at 4:59 PM, Xebar Saram <zeltakc at gmail.com> wrote:> Wow guys > > thank you so much for the quick answers, i really appriciate it :) > > I have another question then if you dont mind. how does one proceed to > randmomly split a single dataset into 90% and 10%? > > thx alot again > > Ethan > > On Thu, Jul 22, 2010 at 7:28 PM, Joshua Wiley <jwiley.psych at gmail.com> wrote: >> On Thu, Jul 22, 2010 at 4:11 PM, jd6688 <jdsignature at gmail.com> wrote: >>> >>> Hi Joshua: >>> >>> how to do a permutation test on the following sample with the sample size in >>> 20000 : >> >> Take a look at some of the results from >> >> RSiteSearch("permutation test") >> >> the "coin" package also comes to mind >> >> Josh >> >> >>> >>> id ? ? ? ?weight ? ? ?P VALUE >>> >>> 100 ? ? ?100 >>> 101 ? ? ? 200 >>> 102 ? ? ? 200 >>> 103 ? ? ? 150 >>> >>> >>> ....... >>> >>> Thanks >>> -- >>> View this message in context: http://r.789695.n4.nabble.com/choosing-a-random-sample-by-precentage-tp2299509p2299529.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. >>> >> >> >> >> -- >> Joshua Wiley >> Ph.D. Student, Health Psychology >> University of California, Los Angeles >> http://www.joshuawiley.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. >> >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
Seemingly Similar Threads
- error using "predict"
- [LLVMdev] [llvm-commits] [cfe-commits] [PATCH] [llvm+clang] memset for non-8-bit bytes
- [LLVMdev] [llvm-commits] [cfe-commits] [PATCH] [llvm+clang] memset for non-8-bit bytes
- [LLVMdev] [cfe-commits] [PATCH] [llvm+clang] memset for non-8-bit bytes
- barchart fails when grouping variable has more than 7 levels (PR#7293)