Description Usage Arguments Details Value Examples
Bulk-typecast columns of a data.frame
. Use with care, will introduce NAs
for impossible casts (like the base R as.* functions)
1 2 3 | df_typecast(x, table_design, silent = FALSE)
df_typecast_list(x, conv, silent)
|
x |
a |
table_design |
a table_design |
silent |
|
conv |
a list of the form list(colname = "coltype") |
df_typecast()
uses a table_design Object to specify column types, while
df_typecast_list()
uses a list
(see examples).
Either a data.frame
or list
with typecasted columns/elements
(depending on the type of x
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | dat <- data.frame(
foo = c('5', '6', '5'),
bar = factor(c('a', 'b', 'c')),
stringsAsFactors = FALSE
)
str(dat)
td <- tabde(
col_name = c("foo", "bar"),
col_type = c("character", "factor")
)
res <- df_typecast(dat, td)
str(res)
res <- df_typecast_list(
dat,
list(foo = "character", bar = "factor")
)
str(res)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.