# [R] Factor levels.

Rolf Turner r.turner at auckland.ac.nz
Wed Oct 3 22:12:07 CEST 2007

```On 4/10/2007, at 7:50 AM, Peter Dalgaard wrote:

> Rolf Turner wrote:
>>> Does it even work? (What if it is the first or the 2nd level that
>>> is absent?
>>
>>     Yes it works.  What's the problem?
>>
>>     To beat it to death:  if the second level of fff is absent
>> then fff will consist entirely of 1's and 3's,
>>     and so c("U","A","S")[fff] will consist entirely of U's and
>> S's.  I can then set the levels to be
>>     c("U","A","S") and get what I want.
> You didn't say that fff was numeric.

All factors are numeric.
> If fff is a factor, then we have the problem:
>
> 0: fff
> 1: Unit
> 2: Scholarship
> 3: Scholarship
> 4: Unit
> 5:
> > c("U","A","S")[fff]
> [1] "A" "U" "U" "A"

My original fff is a factor with levels c
("Unit","Achievement","Scholarship").  If you make that
> Actually we have another problem too, namely sort order....

No, there is no sort order problem.  See above.

[Given that the original fff has its levels in the order specified
then Unit maps to U,
Achievement to A, and Scholarship to S.]

cheers,

Rolf

P.S.  ***Are*** there any risks/dangers in following Christos
Hatzis' suggestion of simply doing

levels(fff) <- c("U","A","S")       ???

######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}

```