[R] only atomic vectors can be sorted ?
ozric@web.de
ozric at web.de
Sun Jan 6 16:01:36 CET 2002
hello,
i want use the crossTableFunction from "Kickstart Document"
and use the iris-Data as example to prepare my dataSets !
....how i should transform the iris dataSet that this function works?
thanks for advance,
christian
xtab<-function(formula,dataframe,dnn=NULL,fieldwidth=10,chisq=F) {
+ if(!missing(formula) && !missing(dataframe)) {
+ xt<-as.character(attr(terms(formula),"variables")[-1])
+ nxt<-length(xt)
+ if(nxt > 2) {
+ by.factor<-as.factor(dataframe[[xt[2]]])
+ factor.levels<-levels(by.factor)
+ nlevels<-length(factor.levels)
+ brkstats<-as.list(rep(0,nlevels))
+ names(brkstats)<-factor.levels
+ for(i in 1:nlevels) {
+ currentdata<-subset(dataframe,by.factor == factor.levels[i])
+ currentcount<-length(currentdata[[1]])
+ totalcount<-length(dataframe[[1]])
+ cat("\nCount for",xt[1],"=",factor.levels[i],"is",
+ currentcount,"(",round(100*currentcount/totalcount,1),"%)\n\n")
+ next.formula<-as.formula(paste(paste("~"),paste(xt[2:nxt],collapse="+")))
+ xtab(next.formula,currentdata,dnn,fieldwidth,chisq)
+ }
+ }
+ else format.xtab(xt[1],xt[2],dataframe,dnn,fieldwidth,chisq)
+ }
+ else cat("Usage: xtab(formula[, dnn=NULL, fieldwidth = 10, chisq = F])\n")
+ }
> names(iris)
[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
> xtab(iris$Sepal.Length~iris$Species,iris)
Error in sort(x) : only atomic vectors can be sorted
______________________________________________________________________________
DSL-Stichtag ist der 31.12.2001 - Sie sparen jetzt noch 135 Euro!
Highspeed-Surfen beim Testsieger + Exklusiv-Prämien: http://dsl.web.de
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list