s-news
[Top] [All Lists]

Re: Permuting a data frame

To: "Walter R. Paczkowski" <dataanalytics@earthlink.net>
Subject: Re: Permuting a data frame
From: "Dimitris Rizopoulos" <dimitrios.rizopoulos@student.kuleuven.ac.be>
Date: Tue, 21 Jun 2005 15:18:59 +0200
Cc: <s-news@lists.biostat.wustl.edu>
References: <E1DkiQC-0002Hp-7r@smtpauth07.mail.atl.earthlink.net>
maybe you can use something like this:

mat <- matrix(1:10, 10, 5)
#########3
n <- nrow(mat)
for(i in 2:ncol(mat)) mat[, i] <- mat[c(seq(n - i + 2, n), seq(1, n - i + 1)), i]
mat


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
    http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm



----- Original Message ----- From: "Walter R. Paczkowski" <dataanalytics@earthlink.net>
To: "S-News" <s-news@lists.biostat.wustl.edu>
Sent: Tuesday, June 21, 2005 3:04 PM
Subject: [S] Permuting a data frame


Good morning,

I have a trivial problem. I want to permute the rows of a data frame with, say, five columns, each column having the same sequence of numbers, 1:n. For example, I want to permute

x1  x2  x3  x4  x5
1    1     1    1    1
2    2     2    2    2
3    3     3    3    3
4    4     4    4    4
5    5     5    5    5

But, after the permutation, there can be no duplications in each row and, of course, each number in each column can appear only once in that column of the resulting data frame . So, I would like something like

x1  x2  x3  x4  x5
1    5    4    3    2
2    1     5   4    3
3    2     1   5    4
4    3     2   1    5
5    4     3   2    1

except the problem I'm working on has 30 rows with five columns.

Is there an easy way to do this? I tried the repeated application of sample with any and duplicated to check for the duplications, but this is very inefficient.

Thanks,

Walt Paczkowski
________________________

Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ  08536
(V) 609-936-8999
(F) 609-936-3733

--------------------------------------------------------------------
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


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