[R] Hmisc interaction behavior
Frank E Harrell Jr
fharrell at virginia.edu
Sun Apr 20 13:22:52 CEST 2003
On Sat, 19 Apr 2003 20:42:29 -0700
Remko Duursma <den.duurs at lycos.com> wrote:
> Dear R-helpers,
> Can someone explain to me why the function interaction() from the Hmisc library results in numeric?
> test1 <- c("A","B","C")
> test2 <- c("D","E","F")
>  TRUE
> I had problems with this side effect in a different function.
> Remko Duursma
interaction in Hmisc returns a factor just as the default interaction. Why that results tests TRUE for is.numeric unlike the default interaction is not clear. The returned objects tests TRUE for is.factor as it should [I seldom use is.numeric but I use is.factor a lot].
The object returned by Hmisc's interaction is created by saying
levels(levs) <- labs
oldClass(levs) <- 'factor'
for reasons of compatibility with S-Plus 6. For R I define oldClass<- as
function (x, value)
class(x) <- value
I should change interaction to use factor( ) instead but I'm curious to know why this problem occurs.
Frank E Harrell Jr Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
More information about the R-help