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")
>
> is.numeric(interaction(test1,test2))
>
> [1] TRUE
>
> I had problems with this side effect in a different function.
>
> thanks,
>
> 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
x
}
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