Skip to content
Prev 127241 / 398500 Next

type conversion

On Wed, 2007-10-17 at 17:20 -0230, Roger Mason wrote:
The value is coming in as a factor:
[1] "character"
[1] "integer"

However, note:
[1] FALSE


In this case, you will likely want to use gsub() to strip the '$' and
the ',' and then convert to numeric:
[1] 149625


Note that the trailing 0's are not printed by default in R, since they
don't represent significant digits. Another example:
[1] 149625.2

However:
[1] 149625.23

This has nothing to do with the way data is stored in R, only the way it
is displayed.

See ?options and review 'digits'.


So, for your data above:

Membersind06$actual06 <- as.numeric(gsub("[^0-9\\.]", "", 
                                    Membersind06$actual06))


See ?gsub and ?regex

HTH,

Marc Schwartz