[R] Quick Question about R
marc_schwartz at comcast.net
Wed Jan 31 20:48:59 CET 2007
On Wed, 2007-01-31 at 14:35 -0500, Konrad wrote:
> Is there a way to convert a character to a number with out getting a
> warning? I have a vector that has both numbers and letters in it and
> I need to convert it to only numbers. At the moment I'm using
> as.numeric but it is generating a warning when it converts a letter.
> Is there another function out there that will do what I need or is
> there a way to turn off the warnings as I don't want the warning to be
> displayed to the end user?
If you provide an example of your data, we can offer more definitive
assistance, especially if the formats are in a regular pattern.
However, you might want to look at:
?gsub (and perhaps ?regex)
One quick example:
> V <- paste(sample(c(LETTERS, 0:9), 20), collapse = "")
> gsub("[A-Z]", "", V)
> as.numeric(gsub("[A-Z]", "", V))
More information about the R-help