[R] sorting factors
Thomas W Blackwell
tblackw at umich.edu
Wed Apr 30 21:33:41 CEST 2003
Try
artic <- factor(as.character(artic),
levels=c("lowlip","dental","apex"),
ordered=T)
Or use the function ordered() instead of factor(),
and omit the last argument above ("ordered=T").
See help("ordered"). I'm not sure whether I even
need the as.character() syntax in there after
read.table(), but it can't hurt.
This is just a guess at an answer, because I'm not
sure I understand quite what question you are asking.
- tom blackwell - u michigan medical school - ann arbor -
On Wed, 30 Apr 2003, g wrote:
> I've been trying to sort the values of the factors of contingency tables
> generated with xtabs. For example, I have a factor called "artic" with three
> possible values that I would like to order in a specific way -- but I'm not
> sure how to go about this.
>
> > test <- read.table("test.tab",header=TRUE,sep="\t")
> > artic = factor(artic,levels=c("lowlip","dental","apex"))
> > test.frame <- as.data.frame(test)
> > test.xtabs <- xtabs(freq ~ artic + var, test.frame)
> > mosaicplot(test.xtabs,shade=TRUE)
>
> Any help appreciated,
> Gina
More information about the R-help
mailing list