[R] Redefine multiple columns (using grep) as factor variables
Johannes Radinger
JRadinger at gmx.at
Fri Jun 1 10:29:06 CEST 2012
Hi,
I have a dataframe with around 100 columns. Now I want
to redefine some of the columns as factors (using as.factor).
Luckily all the names of the columns I want to redefine start with
"crast". Thus I thought I can use grep() for that purpose...
...I found an example for redefining a single column as factor
but that is not working with multiple columns I get from grep()...
what I tried so far:
df[, grep("^crast", colnames(df))] <- as.factor(df[, grep("^crast", colnames(df))])
any suggestions?
cheers,
/Johannes
--
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
More information about the R-help
mailing list