# [R] how to make the matrix as factors

Gabor Grothendieck ggrothendieck at myway.com
Sun Dec 19 14:41:10 CET 2004

```Note that an easy way to get them all to be factors is to add the

leaf <- read.table(...whatever...,  colClasses = "factor")
mca(leaf)

:
: Hi,
:
: The argument df of the function Â'mcaÂ’ requires only a data.frame (not matrix)
: containing only factors.
:
: # Example:
: ?data.frame
:
: library(MASS)
: ?mca
:
: # we  construct the matrix.
: size <- c(3,2,3,3,3,3,3,3,3)
: texture <- c(2,3,2,2,2,2,2,2,2)
: leaf <- cbind(size,texture)
:
: new.mca <- mca(leaf)
:
: # Error in mca(leaf) : All variables must be factors
:
: # now, we construct a data.frame.
: dleaf <- as.data.frame(leaf)
: summary(dleaf)
:
: # we transform each variable into a factor.
: dleaf[,2] <- as.factor(dleaf[,2])
: dleaf[,1] <- as.factor(dleaf[,1])
: summary(dleaf)
: new.mca <- mca(dleaf)
: new.mca
: #
:
: cheers,
:
:
:
: En rÃ©ponse Ã  ys03165003 <at> student.ecnu.edu.cn:
:
: > Hi All,
: >
: > Thanks for you help, I have loaded the library MASS to call the mca. But
: > wen I
: > want to do the mca, there is another problem, for example
: > --------
: > --------
: > > leaf <- read.table("C:/Documents and Settings/wxh-c/Ã—ÃÃƒÃ¦/1.txt",
: > > leaf
: >     size texture
: > 1      3       3
: > 2      2       2
: > 3      3       2
: > 4      3       2
: > 5      3       2
: > 6      3       3
: > 7      3       2
: > 8      3       2
: > 9      3       2
: > > attach(leaf)
: > > require(MASS)
: > [1] TRUE
: > > new.mca <- mca(leaf)
: > Error in mca(leaf) : All variables must be factors
: > ---------
: > So, what should I do to make the matrix as factor. Waiting for you
: > Thanks!
: >
: >                                                                 jeff
: >
: > ______________________________________________
: > R-help <at> stat.math.ethz.ch mailing list
: > https://stat.ethz.ch/mailman/listinfo/r-help
: > http://www.R-project.org/posting-guide.html
: >
: >
:
: ---------------------------------------------------------
: UniversitÃ© Claude Bernard Lyon 1
: UMR CNRS 5023, LEHF
: bat Alphonse Forel
: 43 boulevard du 11 novembre 1918
: F-69622 VILLEURBANNE CEDEX
: FRANCE
: TEL : +33 (0)4 72 44 62 34
: FAX : +33 (0)4 72 43 28 92
: MEL : pierre.bady <at> univ-lyon1.fr
: http://limnologie.univ-lyon1.fr
:
: ______________________________________________
: R-help <at> stat.math.ethz.ch mailing list
: https://stat.ethz.ch/mailman/listinfo/r-help