[R] How to change the class of data?
cskiadas at gmail.com
Thu Jun 12 09:42:23 CEST 2008
Seeing how there have been three wrong answers so far, I should point
1) This is an FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-
2) Most of the other methods suggested so far fail if the example x
used is not of the form 1:n. The only reason they happen to work, is
that in that case the levels coincide with their labels.
 5 6 7 8
 4 3 2 1
> class(x) <- "numeric"
 5 4 3 2
 "5" "6" "7" "8"
Department of Mathematics and Computer Science
On Jun 12, 2008, at 3:07 AM, anna freni sterrantino wrote:
> Hi Selina,
> try ?as.numeric,
> small example
> in the case of a matrix of factor,try
> apply(matrix,1, as.numeric)
> ----- Messaggio originale -----
> Da: Qman Fin <finosaur at gmail.com>
> A: r-help at r-project.org
> Inviato: Giovedì 12 giugno 2008, 8:24:08
> Oggetto: [R] How to change the class of data?
> Hi all,
> I have some data x, which are actualy consisted of numerical
> enties. But the
> class of this matrix is set to be "factor" by someone else. I used
> "class(x)", it turns out to be "factor". So I can not calculate them.
> How can I turn them into numerical data so that I can apply math
> on them? Thanks a lot for your help.
More information about the R-help