[R] coercing factors to matrix() --> num/char ? --
John Thaden
jjthaden at flash.net
Fri Jun 25 15:56:50 CEST 1999
Peter Dalgaard:
>> Hm. I'm not sure there really is much logic in this... Factors are
>> sometimes character-like, sometimes integer-like.
Z. Todd Taylor:
>I'd be interested to hear a discussion of when they need to
>behave like integers.
Yesterday, using S+ 4.5 (Win), for instance:
#Exp is factor containing experiment numbers
>levels(mydata$Exp)
[1] "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
[14] "13" "14" "15" "16" "17" "18" "19"
>lm(y ~ x1 * x2, data=mydata, subset = Exp == 3 | Exp == 5,
+ weights = 5.5 - Exp)
Error in Ops.factor(5.5, Exp): "-" not meaningful for factors
Dumped
>lm(y ~ x1 * x2, data=mydata, subset = Exp == 3 | Exp == 5,
+ weights = 5.5 - as.integer(Exp) )
Error in lm.wfit(X, Y, weights, method): negative weights not allowed
Dumped
# . . . because as.integer(Exp) gives the codes as integers, not the
values, and
# the code for Exp 5 is 6.
> lm(y ~ x1 * x2, data=mydata, subset = Exp == 3 | Exp == 5,
+ weights = 5.5 - as.integer(as.character(Exp)))
Call:
lm(formula = y ~ x1 * x2, data = mydata,
#. . . Remainder of regression report truncated.
Z.T.T.:
>I can see the need to access the integers for
>"lower level" programming, for example, but when else?
ALL of my programming is "lower level"! ;-)
************************************************************
John J. Thaden, Ph.D., Instructor jjthaden at life.uams.edu
Department of Geriatrics (501) 257-5583
University of Arkansas for Medical Sciences FAX: (501) 257-4822
mail & ship to: J. L. McClellan V.A. Medical Center
Research-151 (Room GB103 or GC124)
4300 West 7th Street
Little Rock AR 72205 USA
***********************************************************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list