convert {lazy.tools} | R Documentation |
Convert the columns of a data frame to a specific type/class.
convert(X, what = "factor", func = as.character)
X |
A Data Frame or a Matrix |
what |
A character vector of class names, or "ANY" to match any class
|
func |
The function to be used for the conversion. |
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 )
X with the converted values.
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)