According to Rolf Turner:
|>
|>
|> I still think funny things are going on --- if there aren't bugs then
|> there are annoyingly misleading ``features''.
|>
|> Consider the following:
.....
|> $z:
|> [1] "numeric" # Here junk$z ***has*** been coerced to a factor.
|>
|> Why the difference?
The difference is in the way your junk object is being accessed when
assignments are being made via junk[,'z'] and junk$z
In the latter, only the element named 'z' as part of a list is being
affected. In the former, the default thing to do with dataframes
(i.e. coerce to factors) is happening.
You could have done junk$z <- "something completely silly"
and received no error until you tried to print junk as a dataframe
which would then indicate the lengths of the elements were not equal.
The error would be obvious immediately if you tried to do it with
junk[,'z']
|>
|> Whatever the reason, this business of coercing character to factor
|> in data frames is a real annoyance; it misleads and confuses and
|> disrupts and ought to be done away with.
That's why I routinely unfactor dataframes before I do anything else
to them and specifically make factors when I need them. It avoids
nearly every one of the tricky problems that could arise with lurking
factors.
Two or three years ago I offered to make my unfactor function
available and a few people made use it. It works fine for my purposes
but it's not really for public exhibition -- I could probably code it
much better now. If someone is interested, they might like to
start with it to make something that would be universally usable.
best
--
*************************************************************
Patrick Connolly
HortResearch
Mt Albert It's better to do nothing than to waste time
Auckland ..... Viktoras Kulvinskas
New Zealand
Ph: +64-9 815 4200 x 7188
*************************************************************
|