Learn R Programming

hablar (version 0.1.0)

convert: Convert data type of columns

Description

Convert data type of columns

Usage

convert(.x, ...)

chr(..., .args = list())

lgl(..., .args = list())

int(..., .args = list())

dbl(..., .args = list())

fct(..., .args = list())

dtm(..., .args = list())

dte(..., .args = list())

convert(.x, ...)

Arguments

...

Scoping functions, see details

.args

extra argument to be passed to support function.

.x

A data.frame

Value

a tbl data frame

Details

The convert function requires a scoped function inside. Column names should not be quoted:.

num

Changes to numeric columns. Usage: convert(.df, num(.x, .y) where .x and .y are column names of .df

chr

Changes to character columns. Usage: convert(.df, chr(.x, .y) where .x and .y are column names of .df

int

Changes to integer columns. Usage: convert(.df, int(.x, .y) where .x and .y are column names of .df

lgl

Changes to logical columns. Usage: convert(.df, lgl(.x, .y) where .x and .y are column names of .df

dte

Changes to date columns. Default origin set to "1970-01-01" Usage: convert(.df, dte(.x, .y) where .x and .y are column names of .df

dtm

Changes to date-time columns (POSIXct). Default origin set to "1970-01-01". Usage: convert(.df, dtm(.x, .y) where .x and .y are column names of .df

fct

Changes to factor columns. Usage: convert(.df, fct(.x, .y) where .x and .y are column names of .df

dbl

Changes to numeric columns. Usage: convert(.df, dbl(.x, .y) where .x and .y are column names of .df

It is also possible to use multiple scoping functions inside convert. For example, convert(.df, num(.x), chr(.y)) works as well.

Examples

Run this code
# NOT RUN {
# Changing a columns to numeric
# and another one to character
convert(mtcars, num(gear),
                chr(mpg))


# Changing multiple data types on multiple columns
convert(mtcars, int(hp,
                    wt),
                fct(qsec,
                    cyl,
                    drat))

# }

Run the code above in your browser using DataLab