set_col_types: Set Column Types

Description Usage Arguments Examples

View source: R/set_col_types.R

Description

Set column types in a dataframe using regexes. Separate full or partial column names to look for by |.

Usage

1
2
set_col_types(df, fac_regex = "", num_regex = "", date_regex = "",
  datetm_regex = "", char_regex = "", ...)

Arguments

df

A datafame

fac_regex

A regex of column names to be turned into factors.

num_regex

A regex of column names to be turned numeric.

date_regex

A regex of column names to be turned into dates.

datetm_regex

A regex of column names to be turned into datetimes.

char_regex

A regex of column names to be turned into character.

...

Other arguments

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
my_df <- as.data.frame(list(some = 1:5, column = Sys.Date() + 1:5,
                            types = letters[5:9],
                            to = c("good", "bad", "ugly", "other", "NA"),
                            change = rnorm(10:14)))

factor_cols <- c("change")
char_cols <- c("some|to")

my_new_df <- set_col_types(df = my_df, fac_regex = factor_cols,
                           char_regex = char_cols)
str(my_df)
str(my_new_df)

aedobbyn/dobtools documentation built on May 28, 2019, 2:33 a.m.