Assign a class to a set of column of a data frame. This function is designed to ease the changes of column's class of a given data frame.

assignClass2df(x, colid, cls)

Arguments

x

a data frame or a R object to be coerced into a data frame.

colid

the identity of columns for which class are ti be changed.

cls

a character vector containing the classes' names to be used in the same order as colid. By default cls is repeated until its size equals colid's size.

Value

A data frame for which columns have the required classes.

Examples

df1 <- matrix(signif(runif(20),4), ncol=2) df2 <- assignClass2df(df1, 2, 'character') str(df1)
#> num [1:10, 1:2] 0.0808 0.8343 0.6008 0.1572 0.0074 ...
str(df2)
#> 'data.frame': 10 obs. of 2 variables: #> $ V1: num 0.0808 0.8343 0.6008 0.1572 0.0074 ... #> $ V2: chr "0.8746" "0.1749" "0.03424" "0.3204" ...