Check character values for date/numeric/logical and change datatype
Source:R/other_functions.R
chr2num.Rd
Automatically check a vector, data.frame or list for numeric, logical, date content and change their datatype. Note that factors are skipped in case the user requires character numeric values to be kept as they are.
See also
Other Tools:
autoline()
,
bind_files()
,
bring_api()
,
db_download()
,
db_upload()
,
export_plot()
,
export_results()
,
files_functions()
,
font_exists()
,
formatColoured()
,
formatHTML()
,
get_credentials()
,
glued()
,
grepm()
,
h2o_selectmodel()
,
haveInternet()
,
image_metadata()
,
importxlsx()
,
ip_data()
,
json2vector()
,
list_cats()
,
listfiles()
,
mail_send()
,
markdown2df()
,
move_files()
,
msplit()
,
myip()
,
quiet()
,
read.file()
,
statusbar()
,
tic()
,
try_require()
,
updateLares()
,
warnifnot()
,
what_size()
Examples
str(chr2num(c("1", "2", "3")))
#> num [1:3] 1 2 3
df <- data.frame(A = c("1", "3"), B = c("A", "B"), c = c(pi, pi * 2))
str(chr2num(df))
#> 'data.frame': 2 obs. of 3 variables:
#> $ A: num 1 3
#> $ B: chr "A" "B"
#> $ c: num 3.14 6.28
lst <- list(A = c("1", "2", "3"), B = c("A", "B", "3"), C = pi, D = 3L)
str(chr2num(lst))
#> List of 4
#> $ A: num [1:3] 1 2 3
#> $ B: chr [1:3] "A" "B" "3"
#> $ C: num 3.14
#> $ D: int 3
lst2 <- list(layer1 = ":D", layer2 = lst)
str(chr2num(lst2))
#> List of 2
#> $ layer1: chr ":D"
#> $ layer2:List of 4
#> ..$ A: chr [1:3] "1" "2" "3"
#> ..$ B: chr [1:3] "A" "B" "3"
#> ..$ C: num 3.14
#> ..$ D: int 3
str(chr2logical(c(NA, "true", FALSE)))
#> logi [1:3] NA TRUE FALSE