Learn R Programming

readr (version 0.1.1)

type_convert: Re-convert character columns in existing data frame.

Description

This is useful if you need to do some manual munging - you can read the columns in as character, clean it up with (e.g.) regular expressions and then let readr take another stab at parsing it.

Usage

type_convert(df, col_types = NULL)

Arguments

df
A data frame.
col_types
One of NULL, a list, a named list or a string.

If NULL, the column type will be imputed from the first 30 rows on the input. This is convenient (and fast), but not robust. If the imputation fails, you'll need to supply the

Examples

Run this code
df <- data.frame(
  x = as.character(runif(10)),
  y = as.character(sample(10)),
  stringsAsFactors = FALSE
)
str(df)
str(type_convert(df))

Run the code above in your browser using DataLab