convert {lazy.tools}R Documentation

Convert the columns of a data frame to a specific type/class.

Description

Convert the columns of a data frame to a specific type/class.

Usage

convert(X, what = "factor", func = as.character)

Arguments

X

A Data Frame or a Matrix

what

A character vector of class names, or "ANY" to match any class
where class names can be "factor", "character", "numeric" etc.

func

The function to be used for the conversion.

Details

This function returns
rapply( X, func, classes=what, how="replace" )

The same can be obtained by:
loc <- which( sapply(vartype(X), "%in%", what ) )
X[loc] <- lapply( X[loc], func )

Value

X with the converted values.

Examples

A <- demomat(5,3,root="")
Af <- as.data.frame(A)
Af[,2]=as.numeric(Af[,2])
str(Af)

Ac <- convert( Af )
str(Ac)

Ac <- convert( Af, what=c("factor","numeric") )
str(Ac)


[Package lazy.tools version 0.1.6 ]