[R] strange behaviour of is.factor()

vito muggeo vmuggeo at dssm.unipa.it
Wed Jan 16 11:24:18 CET 2008


Dear all,
It appears that the function is.factor() returns different results when 
used inside the apply() function: that is, is.factor() fails to 
recognize a factor..
Where is the trick?

many thanks,
vito

 > df1<-data.frame(y=1:10,x=rnorm(10),g=factor(c(rep("A",6),rep("B",4))))
 > is.factor(df1[,1])
[1] FALSE
 > is.factor(df1[,2])
[1] FALSE
 > is.factor(df1[,3])
[1] TRUE
 > is.factor(df1$g)
[1] TRUE
 > apply(df1,2,is.factor)
     y     x     g
FALSE FALSE FALSE
 >
 > R.version
                _
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          6.1
year           2007
month          11
day            26
svn rev        43537
language       R
version.string R version 2.6.1 (2007-11-26)
 >

-- 
====================================
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 6626240
fax: 091 485726/485612




More information about the R-help mailing list