Description Usage Arguments Value Author(s) Examples
Convert a vector, list or matrix of numeric-like characters back to numeric values. E.g., percentage, currency, scientific numbers or comma-delimited numbers. Non-numeric-like characters are coerced to NA.
1 2 3 4 5 |
x |
Character in numeric-like values. Either vector, list, matrix or array. |
strict |
Logical, if only convert strict numeric-like characters, e.g, "4.5%" instead of "about 56%". Default TRUE. If FALSE, it will extract the first numeric- like character parts. |
type |
Character vector to define which type of numeric-like characters
to convert. Default |
Numeric values as in the same strcture as x
. Non-numeric-like
values will be coerced to NA.
Yiying Wang, wangy@aetna.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## Not run:
vec <- c("_84%", "32.9%", "33", "a", " -5", "0.3e2", "1,200", "$67")
to_num(vec) # return
# [1] NA 0.329 33.000 NA -5.000 30.000 1200.000 67.000
to_num(vec, strict=FALSE) # return
# [1] 0.840 0.329 33.000 NA -5.000 30.000 1200.000 67.000
to_num('about 56 pounds', strict=FALSE) # return
# [1] 56
to_num(matrix(vec, nrow=2)) # return
# [,1] [,2] [,3] [,4]
# [1,] NA 33 -5 1200
# [2,] 0.329 NA 30 67
to_num(list(list("56%"), list())) # return
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.