Hi, I'me trying to write a function that will shuffle a vector. At the moment I'm baically making a vector of randomized indices and then making a new vector from the original one using these random indices. However, is there an alternative (more elegant) method to do this? I tried help.search('shuffle') but it does'nt return anything relevant. Thanks, ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- Q: What is a dyslexic, agnostic, insomniac? A: Someone who lays awake at night wondering if there really is a dog!
On Monday 10 November 2003 17:28, Rajarshi Guha wrote:> Hi, > I'me trying to write a function that will shuffle a vector. At > the moment I'm baically making a vector of randomized indices and > then making a new vector from the original one using these random > indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything > relevant.Sampling is a more statistical expression for what you are trying to da and I guess something like R> letters[1:5] [1] "a" "b" "c" "d" "e" R> sample(letters[1:5]) [1] "a" "c" "d" "e" "b" is what you want. Z> Thanks, > > ------------------------------------------------------------------- > Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> > GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE > ------------------------------------------------------------------- > > Q: What is a dyslexic, agnostic, insomniac? > A: Someone who lays awake at night wondering if there really is a > dog! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Rajarshi Guha wrote:> Hi, > I'me trying to write a function that will shuffle a vector. At the > moment I'm baically making a vector of randomized indices and then > making a new vector from the original one using these random indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything relevant.sample(x) Uwe Ligges
help(sample) -----Original Message----- From: r-help-bounces at stat.math.ethz.ch on behalf of Rajarshi Guha Sent: Tue 11/11/2003 12:28 AM To: R Cc: Subject: [R] shuffling a vector Hi, I'me trying to write a function that will shuffle a vector. At the moment I'm baically making a vector of randomized indices and then making a new vector from the original one using these random indices. However, is there an alternative (more elegant) method to do this? I tried help.search('shuffle') but it does'nt return anything relevant. Thanks, ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- Q: What is a dyslexic, agnostic, insomniac? A: Someone who lays awake at night wondering if there really is a dog! ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
On Mon, 2003-11-10 at 11:28, Rajarshi Guha wrote:> Hi, > I'me trying to write a function that will shuffle a vector. At the > moment I'm baically making a vector of randomized indices and then > making a new vector from the original one using these random indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything relevant.Seems I sent of the mail prematurely :-/ sample() allows me to get the randomzied indices ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- A mathematician is a device for turning coffee into theorems. -- P. Erdos
This is probably what you want. ?sample HTH, Jim James W. MacDonald Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623>>> Rajarshi Guha <rxg218 at psu.edu> 11/10/03 11:28AM >>>Hi, I'me trying to write a function that will shuffle a vector. At the moment I'm baically making a vector of randomized indices and then making a new vector from the original one using these random indices. However, is there an alternative (more elegant) method to do this? I tried help.search('shuffle') but it does'nt return anything relevant. Thanks, ------------------------------------------------------------------- Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE ------------------------------------------------------------------- Q: What is a dyslexic, agnostic, insomniac? A: Someone who lays awake at night wondering if there really is a dog! ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Rajarshi Guha <rxg218 at psu.edu> writes:> Hi, > I'me trying to write a function that will shuffle a vector. At the > moment I'm baically making a vector of randomized indices and then > making a new vector from the original one using these random indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything relevant.sample(x,length(x)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Mon, 2003-11-10 at 10:28, Rajarshi Guha wrote:> Hi, > I'me trying to write a function that will shuffle a vector. At the > moment I'm baically making a vector of randomized indices and then > making a new vector from the original one using these random indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything relevant. > > Thanks,You might want to look at the permute() function in the 'gregmisc' package. Example:> x <- 1:10 > permute(x)[1] 1 3 2 6 5 7 10 8 9 4 HTH, Marc Schwartz
?sample> Date: Mon, 10 Nov 2003 11:28:56 -0500 > From: Rajarshi Guha <rxg218 at psu.edu> > Sender: r-help-bounces at stat.math.ethz.ch > Organization: > Precedence: list > > Hi, > I'me trying to write a function that will shuffle a vector. At the > moment I'm baically making a vector of randomized indices and then > making a new vector from the original one using these random indices. > > However, is there an alternative (more elegant) method to do this? I > tried help.search('shuffle') but it does'nt return anything relevant. > > Thanks, > > ------------------------------------------------------------------- > Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> > GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE > ------------------------------------------------------------------- > > Q: What is a dyslexic, agnostic, insomniac? > A: Someone who lays awake at night wondering if there really is a dog! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]
rxg218 at psu.edu wrote:> I'me trying to write a function that will shuffle a vector. > At the moment I'm baically making a vector of randomized indices > and then making a new vector from the original one using these > random indices.What's your definition of "elegant"? :-) Isn't this elegant enough? x[order(runif(length(x)))] Peter -- Peter J. Acklam - pjacklam at online.no - http://home.online.no/~pjacklam
Dear Rajarshi, sample(x) will randomly permute the elements of x. I hope that this helps, John At 11:28 AM 11/10/2003 -0500, Rajarshi Guha wrote:>Hi, > I'me trying to write a function that will shuffle a vector. At the >moment I'm baically making a vector of randomized indices and then >making a new vector from the original one using these random indices. > >However, is there an alternative (more elegant) method to do this? I >tried help.search('shuffle') but it does'nt return anything relevant. > >Thanks, > >------------------------------------------------------------------- >Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> >GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE >-------------------------------------------------------------------____________________________ John Fox Department of Sociology McMaster University email: jfox at mcmaster.ca web: http://www.socsci.mcmaster.ca/jfox