% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convert.R
\name{convert}
\alias{convert}
\title{Convert the columns of a data frame to a specific type/class.}
\usage{
convert(X, what = "factor", func = as.character)
}
\arguments{
\item{X}{A Data Frame or a Matrix}

\item{what}{A character vector of class names, or "ANY" to match any class
\cr where class names can be "factor", "character", "numeric" etc.}

\item{func}{The function to be used for the conversion.}
}
\value{
X with the converted values.
}
\description{
Convert the columns of a data frame to a specific type/class.
}
\details{
This function returns \cr
\code{ rapply( X, func, classes=what, how="replace" ) }
\cr\cr
The same can be obtained by:\cr
\code{ loc <- which( sapply(vartype(X), "\%in\%", what ) ) }\cr
\code{ X[loc] <- lapply( X[loc], func ) }\cr
}
\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)

}
