Hi All,
Im interested in creating a function that will convert a variable within a
data.frame to a factor while retaining the original name (yes, I know that I
can just: var -factor(var) but I need it as a function for other
purposes). e.g.:
# this was an attempt but fails.
facts -
How about this? It changes a column to a factor, and
optionally renames it.
facts - function(meta, mod, newmodname) {
meta[,mod] - factor(meta[,mod])
if(!missing(newmodname)) {
colnames(meta)[colnames(meta) == mod] - newmodname
}
meta
}
testdata - data.frame(a=c(1,2,3),
Try this:
transform(DF, newA = factor(a), a = NULL)
On Wed, Mar 17, 2010 at 4:06 PM, AC Del Re de...@wisc.edu wrote:
Hi All,
Im interested in creating a function that will convert a variable within a
data.frame to a factor while retaining the original name (yes, I know that I
can just: var
Wow, wonderful! Thank you for all the response -- and so quick!
ac
On Wed, Mar 17, 2010 at 2:19 PM, Sarah Goslee sarah.gos...@gmail.com
wrote:
How about this? It changes a column to a factor, and
optionally renames it.
facts - function(meta, mod, newmodname) {
meta[,mod] -
4 matches
Mail list logo