Hello all,
Please review the following simple code:
# make a factor:
x - factor(c(one, two))
# what should be the output to the following expression?
c(x, 3)# ===
# I expected it to be as the output of:
c(as.character(x), 3)
# But in fact, the output is what would
Tal:
There was a recent discussion on this list about this (Sam Steingold
was the OP IIRC).
The issue is ?c . In particular:
c is sometimes used for its side effect of removing attributes except
names, for example to turn an array into a vector.
Hence, the factor attribute is removed and you
WARNING: Use with caution!
There is a way to effect the catenation of factors: The data.frame
method for rbind() does this. E.g.
set.seed(42)
f1 - factor(sample(letters[1:3],42,TRUE))
f2 - factor(sample(letters[1:4],66,TRUE))
d1 - data.frame(f=f1)
d2 - data.frame(f=f2)
dd - rbind(d1,d2)
ff
3 matches
Mail list logo