lossless_convert | R Documentation |
Convert the class of a vector to another class – when possible without introducing additional NAs. If NAs would be introduced, the original vector will be returned along with a warning so the user knows it has not been converted.
lossless_convert(x, class)
x |
vector of indeterminate length and type |
class |
character vector of length one specifying the preferred new column type (i.e., 'character', 'numeric', 'integer', or 'factor') |
a vector of the same length as x, but of the new class (when possible)
str(lossless_convert(c('1', '2', '3'), 'integer'))
str(lossless_convert(c('one', '2', '3'), 'integer'))
str(lossless_convert(c('1', '2', 'three'), 'integer'))
str(lossless_convert(c('2020-01-01', '2021-12-31', '2022-02-22'), 'Date'))
str(lossless_convert(c('2020-01-01', '2021-12-31', 'z'), 'Date'))
str(lossless_convert(c('z', '2020-01-01', '2021-12-31'), 'Date'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.