s-news
[Top] [All Lists]

Re: convert factor to numeric

To: "carol white" <wht_crl@yahoo.com>
Subject: Re: convert factor to numeric
From: Daniel_J_Celta@fpl.com
Date: Fri, 12 Oct 2007 11:31:06 -0400
Cc: s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu

You may need to do as follows:
Assuming

> is.factor(size)
[1] T

> as.numeric(as.character(size))

as supposed to

> as.numeric(size)

you should get two completely different answers.

Hope this helps


Daniel J Celta
Project Valuation - Special Valuations
561 691 7653
Inactive hide details for "carol white" <wht_crl@yahoo.com>"carol white" <wht_crl@yahoo.com>




          "carol white" <wht_crl@yahoo.com>
          Sent by: s-news-owner@lists.biostat.wustl.edu

          10/12/2007 11:05 AM



To: s-news@lists.biostat.wustl.edu
cc:
Subject: [S] convert factor to numeric


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

> size
[1] 9 12 26 22 24 13 60 50 20 33 24 32
[13] 12 18 16 19 21 22 12 18 26 28 26 17
[25] 6 23 28 25 12 27 29 21 18 50 24 20
[37] 35 15 18 18 9 13 12 7 14 50 14 13
[49] 33 8 23 23 22 45 14.11 15 25 18 23 16
[61] 11 60 25 18 16 8 25 2 20 28 24 10
[73] 8 46 23 14 38 19 27 8 16 22 18 14
[85] 16 20 23 31 20 24 10 40 12 22 18 10
[97] 22 14 42 18 24.14 18 22 19 14 10 20 17
[109] 65 32 11 27 45 12 13 12 22 22 24 11
[121] 11 21 18 19 24 22 35 23 18 10 33 45
[133] 11 25 23 25 16 18 8 25.25 9 22 22 32
[145] 20 8 10 21 14 20 20 18 22 28 15 25
[157] 19 33 29 17 16 17 20 11 19 13 11 10
[169] 18 20 20 38 20 9 18 42 20 25 13 30
[181] 24 32 23 15 24 21 12 32 28 30 13 18
[193] 20 23 22 15 17 22 22 26 12 19 18 22
[205] 53 38 14 22 32 24 21 14 41 45 8 26
[217] 36 14 24 24 28 18 35 28 50 26 15 16
[229] 130 22 19 65 20 25 19 27 22 28 15 24
[241] 12 24 23 17 26 6 38 19 12
46 Levels: _ 10 11 12 13 130 14 14.11 15 16 17 18 19 2 20 21 22 23 24 ... 9
> as.numeric(size)
[1] 46 4 23 17 19 5 42 39 15 30 19 29 4 12 10 13 16 17 4 12 23 25 23 11 41
[26] 18 25 21 4 24 26 16 12 39 19 15 31 9 12 12 46 5 4 44 7 39 7 5 30 45
[51] 18 18 17 37 8 9 21 12 18 10 3 42 21 12 10 45 21 14 15 25 19 2 45 38 18
[76] 7 33 13 24 45 10 17 12 7 10 15 18 28 15 19 2 34 4 17 12 2 17 7 36 12
[101] 20 12 17 13 7 2 15 11 43 29 3 24 37 4 5 4 17 17 19 3 3 16 12 13 19

[126] 17 31 18 12 2 30 37 3 21 18 21 10 12 45 22 46 17 17 29 15 45 2 16 7 15
[151] 15 12 17 25 9 21 13 30 26 11 10 11 15 3 13 5 3 2 12 15 15 33 15 46 12
[176] 36 15 21 5 27 19 29 18 9 19 16 4 29 25 27 5 12 15 18 17 9 11 17 17 23
[201] 4 13 12 17 40 33 7 17 29 19 16 7 35 37 45 23 32 7 19 19 25 12 31 25 39
[226] 23 9 10 6 17 13 43 15 21 13 24 17 25 9 19 4 19 18 11 23 41 33 13 4

regards,



Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.

GIF image

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