Hi Valery,
does the following work in your data:
levs <- unique.default(Names) factor(Names, levs[order(unique.default(Weights))])
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/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message ----- From: "Khamenia, Valery" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 04, 2004 12:01 PM
Subject: [R] constructing specially ordered factor
Hi all,
my colleagues deal with tables, where every factor is represented in two columns. The first column contains some numeric codes and the second contains the corresponding symbolic name. For example:
ISEX SSEX 0 Female 1 Male 0 Female 0 Female ...
another example:
ICONC SCONC 10 Normal 1000 ExtraHigh 10 Normal 0 Nothing 100 High ...
Colleagues require that the ordering should be done always by numeric column and not by the column with symbolic equivalents.
Here comes the question:
Is it possible to create factor with properly ordered and labeled values in nicer form then in the following long solution:
Factor<-function(Names,Weights) { iunique = !duplicated(Weights) uniqueWeights = Weights[iunique] uniqueNames = Names[iunique] # corresponding unique names factor(Names, uniqueNames[order(uniqueWeights)]) }
Factor(SSEX, ISEX)
Factor(SCONC, ICONC)
Thank you in advance for the comments, Valery.
______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html