s-news
[Top] [All Lists]

Re: convert factor to numeric

To: carol white <wht_crl@yahoo.com>
Subject: Re: convert factor to numeric
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Fri, 12 Oct 2007 08:28:46 -0700
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <899831.38241.qm@web62009.mail.re1.yahoo.com>
Organization: PDF Solutions, Inc.
References: <899831.38241.qm@web62009.mail.re1.yahoo.com>
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)


carol white said the following on 10/12/2007 8:05 AM:
Hi,
it might be a primitive question but how to convert a factor vector to numeric vector? I just have a numeric vector stored as factor and if I want to convert it with as.numeric, I just get a vector with a completely different content of the factor vector


Try:

as.numeric(as.character(size))

or (slightly more efficient)

as.numeric(levels(size)[size])

HTH,

--sundar


<Prev in Thread] Current Thread [Next in Thread>