thank you all.

the dcast formulation is what I am looking for.  That version of the
formula A+D ~ H
also works with the original cast function.

result.cast <- cast(A+D ~ H, value="M", data=meltTest)

It generalizes to a four-factor example, as requested.

This ftable solution didn't do what I wanted because it didn't retain A and
D as factors.

On Mon, Mar 18, 2013 at 6:00 PM, Charles Berry <ccbe...@ucsd.edu> wrote:

> Richard M. Heiberger <rmh <at> temple.edu> writes:
>
> >
> > ## Can someone suggest a simpler expression than either of these, with
> the
> > goal
> > ## of taking a long matrix into a wide one with exactly one of the
> factors
> > converted to
> > ## columns and all the rest retained as factors.  I want something that
> > generalizes beyond
> > ## the three factors illustrated here.
> >
> > ## Rich
> >
> > meltTest <- data.frame(A=rep(c("B","C"), each=12),
> >                        D=rep(c("E","F","G"), each=4, times=2),
> >                        H=rep(c("I","J","K","L"), times=6),
> >                        M=1:24)
> >
>
> amat <- ftable( xtabs( M ~ A + D + H, meltTest ),row.vars=1:2 )
>
> amat is such a matrix with a few attributes added.
>
> HTH,
>
> Chuck
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to