Suppose I have a randomized block experiment with response vector y, treatment factor A, and block factor B. How may I print out the data in a nice two-way array? Here is one solution that I found (data from Steel And Torrie): block <- gl(4,6,24) tnames <- c("Seedling","Early", "Full", "Full/100", "Ripening", "Uninoculated") treat <- gl(6,1,24,label=tnames) content <- scan() 4.4 3.3 4.4 6.8 6.3 6.4 5.9 1.9 4.0 6.6 4.9 7.3 6.0 4.9 4.5 7.0 5.9 7.7 4.1 7.1 3.1 6.4 7.1 6.7 content <- content+30 cmat <- matrix(content,nrow=4,ncol=6,byrow=T) dimnames(cmat) <- list(NULL,tnames) cmat OK, but what if I wanted to do something similar for a two-way array with multiple observations per cell? Or present the cell means? And what about displaying multi-way arrays of data? Murray Jorgensen Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax +64-7 838 4155 Phone +64-7 838 4773 home phone +64-7 856 6705 Mobile +64-21 139 5862 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 5 Sep 2001, Murray Jorgensen wrote:> Suppose I have a randomized block experiment with response vector y, treatment > factor A, and block factor B. How may I print out the data in a nice two-way > array? > > Here is one solution that I found (data from Steel And Torrie): > > block <- gl(4,6,24) > tnames <- c("Seedling","Early", "Full", "Full/100", > "Ripening", "Uninoculated") > treat <- gl(6,1,24,label=tnames) > content <- scan() > 4.4 3.3 4.4 6.8 6.3 6.4 > 5.9 1.9 4.0 6.6 4.9 7.3 > 6.0 4.9 4.5 7.0 5.9 7.7 > 4.1 7.1 3.1 6.4 7.1 6.7 > > content <- content+30 > cmat <- matrix(content,nrow=4,ncol=6,byrow=T) > dimnames(cmat) <- list(NULL,tnames) > cmat > > > OK, but what if I wanted to do something similar for a two-way array with > multiple observations per cell? Or present the cell means? And what about > displaying multi-way arrays of data?xtabs(content ~ block + treat) is almost what you gave, better labelled. The obvious (to me) tools are xtabs and ftable to flatten arrays. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 06:42 AM 5-09-01 +0100, Prof Brian D Ripley wrote:>xtabs(content ~ block + treat) > >is almost what you gave, better labelled. > >The obvious (to me) tools are xtabs and ftable to flatten arrays.Yes, excellent. Thank you. The beginning of the xtabs documentation is a little misleading, though, as it runs> > xtabs > {base} > R Documentation > Cross Tabulation > Description > > Create a contingency table from cross-classifying factors, usually contained > in a data frame, using a formula interface.and I normally expect a contingency table to contain counts. Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax +64-7 838 4155 Phone +64-7 838 4773 home phone +64-7 856 6705 Mobile +64-21 139 5862 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 5 Sep 2001, Murray Jorgensen wrote:> At 06:42 AM 5-09-01 +0100, Prof Brian D Ripley wrote: > > >xtabs(content ~ block + treat) > > > >is almost what you gave, better labelled. > > > >The obvious (to me) tools are xtabs and ftable to flatten arrays. > > Yes, excellent. Thank you. > > The beginning of the xtabs documentation is a little misleading, though, as it > runsRather, I am mis-using the tool, as I happen to know it does this (or rather that crosstabs in S-PLUS can be so abused). Kurt: might it be worth adding an example, e.g.> data(warpbreaks) > warpbreaks$replicate <- rep(1:9, len=54) > ftable(xtabs(breaks ~ wool + tension + replicate, data = warpbreaks))or maybe ftable(xtabs(breaks ~ wool + replicate + tension, data = warpbreaks)) or even tab <- xtabs(breaks ~ wool + replicate + tension, data = warpbreaks) dimnames(tab)[[2]] <- rep("", 9) names(dimnames(tab))[2] <- "" ftable(tab) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._