[R] How to change the class of data?

Moshe Olshansky m_olshansky at yahoo.com
Thu Jun 12 09:03:38 CEST 2008


If x is a vector (one dimensional) then as.numeric(levels(x)) works - I am not sure whether this is the best solution.
If you have a matrix you can use apply, i.e 
x1 <- apply(x,2,function(a) as.numeric(levels(a)))


--- On Thu, 12/6/08, Qman Fin <finosaur at gmail.com> wrote:

> From: Qman Fin <finosaur at gmail.com>
> Subject: [R] How to change the class of data?
> To: r-help at r-project.org
> Received: Thursday, 12 June, 2008, 4:24 PM
> 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 operations
> on them? Thanks a lot for your help.
> 
> Selina
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list