as.numeric.wNames.character | R Documentation |
Converts (1) a 'character' v. into a numeric v., or a 'factor' v. as as.numeric(as.character(vec)) and preserves the original names. The old 'as.numeric.wNames()' is deprecated as it was not clearly documented that it converts via facotr in any case. Code saved at the end.
## S3 method for class 'wNames.character'
as.numeric(vec, verbose = TRUE, factor.to.character = TRUE, ...)
vec |
input vector |
verbose |
Print troubleshooting messages |
factor.to.character |
convert Input vector to first to 'character', then numeric. |
... |
Pass any other argument to as.numeric() |
vec <- as.character(c(1, 2, 8, 9))
names(vec) <- LETTERS[1:4]
vec
as.numeric.wNames.character(vec)
vec2 <- as.factor(c(1, 2, 8, 9))
names(vec2) <- LETTERS[1:4]
vec2
as.numeric.wNames.character(vec2, factor.to.character = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.