Skip to content

convert factor data to numeric

7 messages · Ahmet Temiz, Dimitris Rizopoulos, S Devriese +3 more

#
hello

 could you give me a hint to convert data in factor type to numeric (float) ?

  regards

--
Open WebMail Project (http://openwebmail.org)
#
check the following:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f


Best,
Dimitris
Ahmet Temiz wrote:

  
    
#
On 01/13/2010 10:47 AM, Ahmet Temiz wrote:
you could try as.numeric but without more details it is difficult to see
if this will work. How did you end up with a factor (e.g. through import)?

Stephan
#
S Devriese wrote:
No, don't use as.numeric(). Do follow Dimitris' advice.
But the question of how you got the factor data is good; you
can usually avoid getting factors to begin with.

  -Peter Ehlers

  
    
#
Hello,

I find a way to convert data in factor type to numeric :
data_numeric <- as.numeric(as.character(data_factor)).
It's treaky but works.


Peter Ehlers a ?crit :

  
    
#
On 01/13/2010 05:41 PM, Peter Ehlers wrote:
I know, slightly sloppy answer (see Dimitri's answer), but I hoped to
find out how he got the factor in the first place, because if it is an
import issue (and e,g. decimal character is different from the locale
decimal character) the FAQ answer might not work as expected.

Stephan
#
On 14/01/2010, at 6:00 AM, Nathalie Yauschew-Raguenes wrote:

            
Possibly even more ``treaky'' but more efficient is:

	data_numeric <- as.numeric(levels(data_factor)[data_factor])

as has been pointed out quite a few times on this list.

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}