[R] Factor levels.
Rolf Turner
r.turner at auckland.ac.nz
Wed Oct 3 21:32:43 CEST 2007
On 3/10/2007, at 5:10 PM, Christos Hatzis wrote:
> Would
>
> levels(fff) <- c("A","S","U")
>
> not work?
Well, not quite. This would scramble the levels. The levels of the
original fff are
c("Unit","Achieved","Scholarship") --- i.e. they are ***not*** in
alphabetical order.
But your suggestion modified to
levels(fff) <- c("U","A","S")
does indeed seem to work.
I had a clear and distinct recollection of having tried something
like this previously
and getting a factor consisting entirely of NAs (since none of the
assigned levels
matched any of the existing levels). But my clear and distinct
recollection appears
to have been a load of dingos' kidneys.
I now believe that what I was recollecting was the fact that
fff <- factor(fff,levels=c("U","A","S"))
gives a factor consisting of nothing but NAs. Subtly (???) different.
I have a nagging feeling that there is some risk associated with
your suggestion,
as compared with Peter Dalgaard's. But I can't see what that risk
would actually be.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}
More information about the R-help
mailing list