Last chance! 50% off unlimited learning
Sale ends in
type_convert(df, col_types = NULL, na = c("", "NA"), trim_ws = TRUE, locale = default_locale())
NULL
, a cols
, specification of
a string. See vignette("column-types")
for more details. If NULL
, all column types will be imputed from the first 1000 rows
on the input. This is convenient (and fast), but not robust. If the
imputation fails, you'll need to supply the correct types yourself.
If a column specification created by cols
, it must contain
one "collector
" for each column. If you only want to read a
subset of the columns, use cols_only
.
Alternatively, you can use a compact string representation where each
character represents one column:
c = character, i = integer, n = number, d = double,
l = logical, D = date, T = date time, t = time, ? = guess, or
_
/-
to skip the column.
character()
to indicate no missing values.locale
to create your own locale that controls things like
the default time zone, encoding, decimal mark, big mark, and day/month
names.df <- data.frame(
x = as.character(runif(10)),
y = as.character(sample(10)),
stringsAsFactors = FALSE
)
str(df)
str(type_convert(df))
df <- data.frame(x = c("NA", "10"), stringsAsFactors = FALSE)
str(type_convert(df))
Run the code above in your browser using DataLab