Reputation: 3057
I have such a value:
" 0.67564;"
and I want to delete ;
and only have the double value. how can I do it in r?
Upvotes: 1
Views: 92
Reputation: 4335
I would probably use
as.numeric(gsub("[^[:alnum:]///' ]", "", " 0.67564;"))
Can also be done using regex
[^[:alnum:]]
is preferred to [^0-9A-Za-z]
. ?regex
says "because their interpretation is locale- and implementation-dependent, they are best avoided." and "For example, [[:alnum:]]
means [0-9A-Za-z]
, except the latter depends upon the locale and the character encoding, whereas the former is independent of locale and character set
Upvotes: 1
Reputation: 25608
a <- " 0.67564;"
gsub(';', '', a)
[1] " 0.67564"
To get a numeric representation:
as.numeric(gsub(';', '', a))
[1] 0.67564
Upvotes: 3