[R] constructing specially ordered factor
Khamenia, Valery
V.Khamenia at biovision-discovery.de
Mon Oct 4 12:01:12 CEST 2004
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.
More information about the R-help
mailing list