[R] Fwd: (no subject)

From: David Barron <mothsailor_at_googlemail.com>
Date: Tue 12 Sep 2006 - 13:09:08 GMT

>From the FAQ:

7.10 How do I convert factors to numeric?

It may happen that when reading numeric data into R (usually, when reading in a file), they come in as factors. If f is such a factor object, you can use

     as.numeric(as.character(f))

to get the numbers back. More efficient, but harder to remember, is

     as.numeric(levels(f))[as.integer(f)]

In any case, do not call as.numeric() or their likes directly for the task at hand (as as.numeric() or unclass() give the internal codes).

On 12/09/06, Anders Eklund <aeklund@kth.se> wrote:
> Hi,
>
> I have a problem with aggregate.
>
> x <- aggregate(t1,list(t2,t3,t4), mean)
>
> z<-x[,3]
>
> I want z to be a vector but it is a factor.
>
> I've tried to use as.vector(z,mode="numeric") but then the numbers get
> scrambeled.
>
> Any help is appriciated
>
> /anders
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

--
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP


-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Tue Sep 12 23:13:47 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 13:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.