Dear all, I would like to randomly split a sample in two equally large subsamples. The sample data is stored as a matrix with each row representing an individual and each column representing some variable (e.g., name, age, sex, etc.); the first row contains the names of the variables; the first column contains the individual number (1:n, for n individuals); the number of individuals is even (so, the overall number of rows is odd). I found similar threads (like "random subset"), but I don't know how to apply the information from them in my case. Could somebody help me a little bit? Thanks in advance! Yoan
Hi Yoan, Please try ?sample. Suppose you have 1:n ids of total observations where n is even, you want to randomly split it into two subsamples, the following code should work. n <- 20 one.sample <- sort(sample(1:n, n/2)) another.sample <- (1:n)[-one.sample] Good luck. Wu ----- A R learner. -- View this message in context: r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021257.html Sent from the R help mailing list archive at Nabble.com.
Thanks, it works! -- View this message in context: r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021365.html Sent from the R help mailing list archive at Nabble.com.