s-news
[Top] [All Lists]

Re: Random "shuffling" of a dataframe based on a column

To: "Khan, Sohail" <khan@cshl.edu>, s-news@lists.biostat.wustl.edu
Subject: Re: Random "shuffling" of a dataframe based on a column
From: Mario Cortina Borja <M.Cortina@ich.ucl.ac.uk>
Date: Tue, 26 Jul 2005 16:06:26 +0100
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A90DDCF3@mailbox02.cshl.edu>

Dear Sohail,

df1[ sample(1:dim(df1)[1]), ]

does that,

Best wishes,
Mario

At 10:48 AM 7/26/2005 -0400, Khan, Sohail wrote:
Dear List,

Is there a way to "shuffle" a data frame based on a column. I.E. if the data frame looks like:
pos    ratio
1       0.2356
2       0.5236
3       1.2356
4       2.5690

I would like to randomly shuffle based on column pos so data frame looks like:

pos    ratio
3       1.2356
1       0.2356
4       2.5690
2       0.5236

I would really appreciate your help.  Thanks.


Sohail Khan
Scientific Programmer
COLD SPRING HARBOR LABORATORY
Genome Research Center
500 Sunnyside Boulevard
Woodbury, NY 11797
(516)422-4076

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

_______________________
Dr Mario Cortina Borja
Senior Lecturer in Statistics
M.Cortina@ich.ucl.ac.uk  Phone +44(0)20 7905 2113 Fax +44(0)20 7905 2381
Paed. Epid. & Biostats, Institute of Child Health, UCL, London WC1N 1EH, UK


<Prev in Thread] Current Thread [Next in Thread>