Convert columns of a data frame to certain types

Share:

Description

Convert columns of a data frame to certain types

Usage

1
correctTypes(dat, col_names = NULL, types)

Arguments

dat

data.frame The data frame whose types you want to change.

col_names

character. Names of columns, the types of which you want to change.

types

character. Names of new types. Should be the same length as col_names

Value

data.frame. With specified classes.

Author(s)

Kaiyin Zhong, Fan Liu

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
dat = randNormDat(3, 3)
dat[, 2] = as.character(dat$V2)
dat1 = correctTypes(dat, types = rep("numeric", 3))
all(colClasses(dat1) == rep("numeric", 3))
dat2 = correctTypes(dat, 2, "numeric")
all(colClasses(dat2) == rep("numeric", 3))

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.