as.factor does not accept levels as an argument. use the first form that you have
factor(ch1, levels=ch1) On Wed, Apr 8, 2009 at 7:36 AM, Heinz Tuechler <tuech...@gmx.at> wrote: > Dear All, > > to my surprise as.factor does not accept a levels argument. Maybe I did not > read the documentation well enough. See the example below. I wanted to use > ch1 as factor in the newdata argument of survfit, so I assumed that I could > write as.factor(ch1, levels=ch1), since the order should be kept. > > But as.factor(ch1, levels=ch1) results in the error: > > Error in as.factor(ch1, levels = ch1) : > unused argument(s) (levels = c("low", "inter", "high")) > > factor(ch1, levels=ch1) works as I expected. > Is it intended that as.factor does not use the levels argument? > > Thanks, > > Heinz > > ch1 <- c('low', 'inter', 'high') > factor(ch1) > factor(ch1, levels=ch1) > as.factor(ch1, levels=ch1) > >> version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status Patched > major 2 > minor 8.1 > year 2009 > month 03 > day 13 > svn rev 48132 > language R > version.string R version 2.8.1 Patched (2009-03-13 r48132) >> sessionInfo() > R version 2.8.1 Patched (2009-03-13 r48132) > i386-pc-mingw32 > > locale: > LC_COLLATE=German_Switzerland.1252;LC_CTYPE=German_Switzerland.1252;LC_MONETARY=German_Switzerland.1252;LC_NUMERIC=C;LC_TIME=German_Switzerland.1252 > > attached base packages: > [1] splines stats graphics grDevices utils datasets methods > [8] base > > other attached packages: > [1] survival_2.34-1 car_1.2-12 gmodels_2.14.1 gdata_2.4.2 > [5] Hmisc_3.5-2 > > loaded via a namespace (and not attached): > [1] cluster_1.11.12 grid_2.8.1 gtools_2.5.0-1 lattice_0.17-20 > [5] MASS_7.2-46 >> > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.